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:
987 bytes
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * This program is written according to the example described in
|
|---|
| 3 | * http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-1.1/node86.htm#Node86
|
|---|
| 4 | */
|
|---|
| 5 | #include<stdio.h>
|
|---|
| 6 | #include<mpi.h>
|
|---|
| 7 | #include<assert.h>
|
|---|
| 8 |
|
|---|
| 9 | int main(int argc, char* argv[]){
|
|---|
| 10 | int rank;
|
|---|
| 11 | int procs;
|
|---|
| 12 | int* sendBuf;
|
|---|
| 13 | int* rcvBuf;
|
|---|
| 14 | int* sum;
|
|---|
| 15 | int buf1, buf2;
|
|---|
| 16 |
|
|---|
| 17 | MPI_Init(&argc,&argv);
|
|---|
| 18 | MPI_Comm_size(MPI_COMM_WORLD, &procs);
|
|---|
| 19 | MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|---|
| 20 |
|
|---|
| 21 | if(procs != 2){
|
|---|
| 22 | printf("This program requires exactly two processes.\n");
|
|---|
| 23 | return 1;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | buf1=rank;
|
|---|
| 27 | buf2=rank;
|
|---|
| 28 |
|
|---|
| 29 | switch(rank){
|
|---|
| 30 | case 0:
|
|---|
| 31 | MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 32 | MPI_Bcast(&buf2, 1, MPI_INT, 1, MPI_COMM_WORLD);
|
|---|
| 33 | break;
|
|---|
| 34 | case 1:
|
|---|
| 35 | MPI_Bcast(&buf2, 1, MPI_INT, 1, MPI_COMM_WORLD);
|
|---|
| 36 | MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|---|
| 37 | break;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | printf("process %d: buf1=%d, buf2=%d\n", rank, buf1, buf2);
|
|---|
| 41 | assert(buf1==0 && buf2 == 1);
|
|---|
| 42 |
|
|---|
| 43 | MPI_Finalize();
|
|---|
| 44 | return 0;
|
|---|
| 45 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.