deadlock5.cpp 650 Bytes
Newer Older
Panagiotis's avatar
Panagiotis committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Example codes for HPC course
// (c) 2012 Matthias Troyer, ETH Zurich

#include <iostream>
#include <string>
#include <mpi.h>

int main(int argc, char** argv) {
  MPI_Status status;
  int num;
  
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD,&num);
  
  double ds=3.1415927; // to send
  double dr;           // to receive
  int tag=99;
  
  if(num==0) {
    MPI_Send(&ds,1,MPI_DOUBLE,1,tag,MPI_COMM_WORLD);
    MPI_Recv (&dr,1,MPI_DOUBLE,1,tag,MPI_COMM_WORLD,&status);
  }
  else {
    MPI_Send(&ds,1,MPI_DOUBLE,0,tag,MPI_COMM_WORLD);
    MPI_Recv (&dr,1,MPI_DOUBLE,0,tag,MPI_COMM_WORLD,&status);
  }
  
  MPI_Finalize();
  return 0;
}