main
|
Last change
on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Rev | Line | |
|---|
| [18cffb4] | 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include "mpi.h"
|
|---|
| 4 |
|
|---|
| 5 | /**
|
|---|
| 6 | * This example demonstrates the usage of MPI collective operations,
|
|---|
| 7 | * which should be called in the same orders for all MPI processes.
|
|---|
| 8 | * This example has an error when there are more than five MPI processes.
|
|---|
| 9 | */
|
|---|
| 10 | #include<mpi.h>
|
|---|
| 11 |
|
|---|
| 12 | int main(int argc, char *argv[]) {
|
|---|
| 13 | int rank, size, i, n;
|
|---|
| 14 |
|
|---|
| 15 | MPI_Init(&argc, &argv);
|
|---|
| 16 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 17 | MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|---|
| 18 |
|
|---|
| 19 | int sendbuf[size];
|
|---|
| 20 | int recvbuf;
|
|---|
| 21 |
|
|---|
| 22 | if(rank == 0){
|
|---|
| 23 | for (int i=0; i<size; i++)
|
|---|
| 24 | sendbuf[i] = 1 + rank + size*i;
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | if(rank != 6)
|
|---|
| 28 | MPI_Bcast(sendbuf, size, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 29 |
|
|---|
| 30 | printf("Proc %d: ", rank);
|
|---|
| 31 | for (int i=0; i<size; i++) printf("%d ", sendbuf[i]);
|
|---|
| 32 | printf("\n");
|
|---|
| 33 |
|
|---|
| 34 | int recvcounts[size];
|
|---|
| 35 | for (int i=0; i<size; i++)
|
|---|
| 36 | recvcounts[i] = 1;
|
|---|
| 37 |
|
|---|
| 38 | MPI_Reduce_scatter(sendbuf, &recvbuf, recvcounts, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
|
|---|
| 39 |
|
|---|
| 40 | printf("Proc %d: %d\n", rank, recvbuf);
|
|---|
| 41 |
|
|---|
| 42 | MPI_Finalize();
|
|---|
| 43 |
|
|---|
| 44 | return 0;
|
|---|
| 45 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.