This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <mpi.h>
13
14 static MPI_T_pvar_handle count_handle;
15 static const char count_pvar_name[] = "pml_monitoring_messages_count";
16 static int count_pvar_idx;
17
18 int main(int argc, char**argv)
19 {
20 int rank, size, n, to, from, tagno, MPIT_result, provided, count;
21 MPI_T_pvar_session session;
22 MPI_Status status;
23 MPI_Request request;
24 MPI_Comm comm = MPI_COMM_WORLD;
25 size_t*counts;
26
27 n = -1;
28 MPI_Init(&argc, &argv);
29 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 MPI_Comm_size(MPI_COMM_WORLD, &size);
31 to = (rank + 1) % size;
32 from = (rank + size - 1) % size;
33 tagno = 201;
34
35 MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided);
36 if (MPIT_result != MPI_SUCCESS)
37 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
38
39 MPIT_result = MPI_T_pvar_get_index(count_pvar_name, MPI_T_PVAR_CLASS_SIZE, &count_pvar_idx);
40 if (MPIT_result != MPI_SUCCESS) {
41 printf("cannot find monitoring MPI_T \"%s\" pvar, check that you have monitoring pml\n",
42 count_pvar_name);
43 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
44 }
45
46 MPIT_result = MPI_T_pvar_session_create(&session);
47 if (MPIT_result != MPI_SUCCESS) {
48 printf("cannot create a session for \"%s\" pvar\n", count_pvar_name);
49 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
50 }
51
52
53 MPIT_result = MPI_T_pvar_handle_alloc(session, count_pvar_idx,
54 &comm, &count_handle, &count);
55 if (MPIT_result != MPI_SUCCESS) {
56 printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n",
57 count_pvar_name);
58 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
59 }
60
61 counts = (size_t*)malloc(count * sizeof(size_t));
62
63 MPIT_result = MPI_T_pvar_start(session, count_handle);
64 if (MPIT_result != MPI_SUCCESS) {
65 printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n",
66 count_pvar_name);
67 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
68 }
69
70
71 if (rank == 0) {
72 n = 25;
73 MPI_Isend(&n,1,MPI_INT,to,tagno,MPI_COMM_WORLD,&request);
74 }
75 while (1) {
76 MPI_Irecv(&n, 1, MPI_INT, from, tagno, MPI_COMM_WORLD, &request);
77 MPI_Wait(&request, &status);
78 if (rank == 0) {n--;tagno++;}
79 MPI_Isend(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD, &request);
80 if (rank != 0) {n--;tagno++;}
81 if (n<0){
82 break;
83 }
84 }
85
86 MPIT_result = MPI_T_pvar_read(session, count_handle, counts);
87 if (MPIT_result != MPI_SUCCESS) {
88 printf("failed to read handle on \"%s\" pvar, check that you have monitoring pml\n",
89 count_pvar_name);
90 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
91 }
92
93
94 MPI_Allreduce(MPI_IN_PLACE, counts, count, MPI_UNSIGNED_LONG, MPI_MAX, MPI_COMM_WORLD);
95
96 if(0 == rank) {
97 for(n = 0; n < count; ++n)
98 printf("%zu%s", counts[n], n < count - 1 ? ", " : "\n");
99 }
100
101 free(counts);
102
103 MPIT_result = MPI_T_pvar_stop(session, count_handle);
104 if (MPIT_result != MPI_SUCCESS) {
105 printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n",
106 count_pvar_name);
107 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
108 }
109
110 MPIT_result = MPI_T_pvar_handle_free(session, &count_handle);
111 if (MPIT_result != MPI_SUCCESS) {
112 printf("failed to free handle on \"%s\" pvar, check that you have monitoring pml\n",
113 count_pvar_name);
114 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
115 }
116
117 MPIT_result = MPI_T_pvar_session_free(&session);
118 if (MPIT_result != MPI_SUCCESS) {
119 printf("cannot close a session for \"%s\" pvar\n", count_pvar_name);
120 MPI_Abort(MPI_COMM_WORLD, MPIT_result);
121 }
122
123 (void)MPI_T_finalize();
124
125 MPI_Finalize();
126
127 return EXIT_SUCCESS;
128 }