-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_coll_v2.c
100 lines (65 loc) · 2.44 KB
/
example_coll_v2.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>
#define Y_DIM 3
int main(int rgc, char *argv[])
{
int res;
int rank, size;
MPI_Init(NULL,NULL);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
fprintf(stdout,"Process %i out of %i\n",rank,size);
assert(size%DIMS_Y == 0);
MPI_Comm topo_comm;
MPI_Request topo_request;
// Request the creation of a 2-D Torus
// More a naming scheme than a real topology
int ndims = 2;
int dims[ndims];
dims[0] = size/Y_DIM;
dims[1] = Y_DIM;
int periods[ndims] = {1, 1};
int reorder = 1; // allow for "intial" processes to be reordered b/c "Row-major
// numbering is always used for the processes in a Cartesian
// structure"
// Is reorder useful for other graph naming schemes then? (e.g
// MPI_Igraph_create or MPI_Idist_graph_create )
// Naming scheme creation
MPI_Icart_coords_create(MPI_COMM_WORLD, ndims, dims, periods, reorder, &topo_comm, &topo_request); // new api
int out_dims[ndims] = {0};
int out_periods[ndims] = {0};
int new_coods[dims] = {0};
int new_rank;
MPI_Cart_get(topo_comm,ndims,out_dims,out_periods,new_coords);
MPI_Cart_rank(topo_comm,new_coords,&new_rank);
fprintf(stdout,(new_rank == 0) ?
"I'm root process in cart comm (rank in COMM_WORLD %i)\n" :
"Not root process (rank in COMM_WORLD %i)\n",rank);
MPI_Request bcast_request;
MPI_Bcast_init(MPI_BUFFER_DEFERRED,MPI_COUNT_DEFERRED,MPI_INT,0,topo_comm,MPI_INFO_NULL,&bcast_request);
//MPI_Request reduction_request;
// Schedule another op.
//
//MPI_Allreduce_init(MPI_BUFFER_DEFERRED, MPI_BUFFER_DEFERRED, 1, MPI_INT, MPI_SUM, topo_comm, MPI_INFO_NULL, &reduction_request);
MPI_Wait(&bcast_request, MPI_STATUS_IGNORE);
MPI_Cart_get(topo_comm,ndims,out_dims,out_periods,new_coords);
MPI_Cart_rank(topo_comm,new_coords,&new_rank);
int count = 1;
void *add_array[count] = {NULL};
int data = 0;
if( !new_rank )
data = 333;
add_array[0] = &data;
MPI_Params_register(bcast_request, count, add_array, 0, NULL);
MPI_Start(&bcast_request);
//MPI_Start(&reduction_request);
// Do some work here
MPI_Wait(&bcast_request);
// MPI_Wait(&reduction_request);
MPI_Request_free(&bcast_request);
//MPI_Request_free(&reduction_request);
MPI_Comm_disconnect(topo_comm);
MPI_Finalize();
exit(EXIT_SUCCESS);
}