-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpi_bug2.c
44 lines (39 loc) · 1.17 KB
/
mpi_bug2.c
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/******************************************************************************
* FILE: mpi_bug2.c
* DESCRIPTION:
* This program has a bug that causes wrong answers and/or termination - depends
* upon the MPI library and platform.
* SOURCE: Blaise Barney
* LAST REVISED: 01/24/09
******************************************************************************/
#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[])
{
int numtasks, rank, tag=1, alpha, i;
float beta;
MPI_Request reqs[10];
MPI_Status stats[10];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
if (numtasks > 2)
printf("Numtasks=%d. Only 2 needed. Ignoring extra...\n",numtasks);
for (i=0; i<10; i++) {
alpha = i*10;
MPI_Isend(&alpha, 1, MPI_INT, 1, tag, MPI_COMM_WORLD, &reqs[i]);
MPI_Wait(&reqs[i], &stats[i]);
printf("Task %d sent = %d\n",rank,alpha);
}
}
if (rank == 1) {
for (i=0; i<10; i++) {
MPI_Irecv(&beta, 1, MPI_FLOAT, 0, tag, MPI_COMM_WORLD, &reqs[i]);
MPI_Wait(&reqs[i], &stats[i]);
printf("Task %d received = %f\n",rank,beta);
}
}
MPI_Finalize();
}