-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestcoll2.c
78 lines (62 loc) · 1.66 KB
/
testcoll2.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// SPDX-License-Identifier: MIT
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef NOWRAP
#include <mpi.h>
#else
#include "mpi.h"
#endif
int main(int argc, char* argv[])
{
int rc;
rc = MPI_Init(&argc,&argv);
int n = (argc > 1) ? atoi(argv[1]) : 1000;
int me, np;
MPI_Comm_rank(MPI_COMM_WORLD,&me);
MPI_Comm_size(MPI_COMM_WORLD,&np);
//printf("I am %d of %d\n", me, np);
if (me==0) printf("nonblocking collectives: %d iterations\n", n);
{
if (me==0) printf("MPI_Ibcast\n");
MPI_Request * r = calloc(n,sizeof(MPI_Request));
int * x = calloc(n,sizeof(int));
for (int i=0; i<n; i++) {
x[i] = np - me;
}
for (int i=0; i<n; i++)
{
MPI_Ibcast(&x[i], 1, MPI_INT, 0, MPI_COMM_WORLD, &r[i]);
}
MPI_Barrier(MPI_COMM_WORLD);
for (int i=0; i<n; i++)
{
MPI_Wait(&r[i],MPI_STATUS_IGNORE);
// verify that waiting on MPI_REQUEST_NULL is okay
MPI_Wait(&r[i],MPI_STATUS_IGNORE);
}
int errors = 0;
for (int i=0; i<n; i++) {
errors += (x[i] != np);
}
if (errors) {
printf("errors: %d\n", errors);
fflush(0);
for (int i=0; i<n; i++) {
printf("x[%d] = %d\n",i,x[i]);
}
fflush(0);
usleep(1);
MPI_Abort(MPI_COMM_WORLD,errors);
}
}
MPI_Barrier(MPI_COMM_WORLD);
fflush(0);
usleep(1);
MPI_Barrier(MPI_COMM_WORLD);
if (me==0) printf("all done\n");
rc = MPI_Finalize();
return rc;
}