source: CIVL/mods/dev.civl.com/examples/mpi/collective/bcast_bug2.c@ cb4d4f4

main test-branch
Last change on this file since cb4d4f4 was aad342c, checked in by Stephen Siegel <siegel@…>, 3 years ago

Performing huge refactor to incorporate ABC, GMC, and SARL into CIVL repo and use Java modules.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5664 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.5 KB
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 Process zero executes a broadcast, followed by a blocking send operation. Process one first executes a blocking receive that matches the send, followed by broadcast call that matches the broadcast of process zero. This program may deadlock. The broadcast call on process zero may block until process one executes the matching broadcast call, so that the send is not executed. Process one will definitely block on the receive and so, in this case, never executes the broadcast.
6 */
7#include<stdio.h>
8#include<mpi.h>
9#include<assert.h>
10
11int main(int argc, char* argv[]){
12 int rank;
13 int procs;
14 int* sendBuf;
15 int* rcvBuf;
16 int* sum;
17 int buf1, buf2;
18
19 MPI_Init(&argc,&argv);
20 MPI_Comm_size(MPI_COMM_WORLD, &procs);
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22
23 if(procs != 2){
24 printf("This program requires exactly two processes.\n");
25 return 1;
26 }
27
28 if(rank == 0){
29 buf1=1;
30 buf2=2;
31 }
32
33 switch(rank) {
34 case 0:
35 MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
36 MPI_Send(&buf2, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
37 break;
38 case 1:
39 MPI_Recv(&buf2, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
40 MPI_Bcast(&buf1, 1, MPI_INT, 0, MPI_COMM_WORLD);
41 break;
42 }
43
44 printf("process %d: buf1=%d, buf2=%d\n", rank, buf1, buf2);
45 assert(buf1==1 && buf2 == 2);
46
47 MPI_Finalize();
48 return 0;
49}
Note: See TracBrowser for help on using the repository browser.