/* Use a global variable to inhibit compiler optimizations in the compute
* function. */
double junk = 0.0;
-
-void compute(int step, double *data) {
+void compute(int step, double *data);
+void compute(int step, double *data)
+{
int i;
for (i = 0; i < N; i++)
junk += data[i] * (double) step;
}
-int main( int argc, char *argv[] )
+int main(int argc, char *argv[])
{
int i, rank, nproc;
int errors = 0, all_errors = 0;
MPI_Request put_req[M] = { MPI_REQUEST_NULL };
MPI_Request get_req;
double *baseptr;
- double data[M][N]; /* M buffers of length N */
+ double data[M][N]; /* M buffers of length N */
+ MPI_Info win_info;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
assert(M < NSTEPS);
- MPI_Win_allocate(NSTEPS*N*sizeof(double), sizeof(double), MPI_INFO_NULL,
+ MPI_Info_create(&win_info);
+
+#ifdef USE_WIN_ALLOC_SHM
+ MPI_Info_set(win_info, (char*)"alloc_shm", (char*)"true");
+#else
+ MPI_Info_set(win_info, (char*)"alloc_shm", (char*)"false");
+#endif
+
+ MPI_Win_allocate(NSTEPS * N * sizeof(double), sizeof(double), win_info,
MPI_COMM_WORLD, &baseptr, &win);
MPI_Win_lock_all(0, win);
for (i = 0; i < NSTEPS; i++) {
- int target = (rank+1) % nproc;
+ int target = (rank + 1) % nproc;
int j;
/* Find a free put request */
if (i < M) {
j = i;
- } else {
+ }
+ else {
MPI_Waitany(M, put_req, &j, MPI_STATUS_IGNORE);
}
- MPI_Rget(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win,
- &get_req);
- MPI_Wait(&get_req,MPI_STATUS_IGNORE);
+ MPI_Rget(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &get_req);
+ MPI_Wait(&get_req, MPI_STATUS_IGNORE);
compute(i, data[j]);
- MPI_Rput(data[j], N, MPI_DOUBLE, target, i*N, N, MPI_DOUBLE, win,
- &put_req[j]);
+ MPI_Rput(data[j], N, MPI_DOUBLE, target, i * N, N, MPI_DOUBLE, win, &put_req[j]);
}
MPI_Win_free(&win);
+ MPI_Info_free(&win_info);
+
MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
if (rank == 0 && all_errors == 0)