#include "stdio.h"
#include "stdlib.h"
#include "mpitest.h"
/* This is the tree-based scalable version of the fetch-and-add
example from Using MPI-2, pg 206-207. The code in the book (Fig
#include "stdio.h"
#include "stdlib.h"
#include "mpitest.h"
/* This is the tree-based scalable version of the fetch-and-add
example from Using MPI-2, pg 206-207. The code in the book (Fig
-int localvalue=0; /* contribution of this process to the counter. We
- define it as a global variable because attribute
- caching on the window is not enabled yet. */
+int localvalue = 0; /* contribution of this process to the counter. We
+ * define it as a global variable because attribute
+ * caching on the window is not enabled yet. */
void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
int rank, nprocs, i, *counter_mem, *get_array, *get_idx, *acc_idx,
mask, nlevels, level, idx, tmp_rank, pof2;
MPI_Datatype get_type, acc_type;
MPI_Win win;
int errs = 0, *results, *counter_vals;
int rank, nprocs, i, *counter_mem, *get_array, *get_idx, *acc_idx,
mask, nlevels, level, idx, tmp_rank, pof2;
MPI_Datatype get_type, acc_type;
MPI_Win win;
int errs = 0, *results, *counter_vals;
-
- MTest_Init(&argc,&argv);
- MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
- MPI_Comm_rank(MPI_COMM_WORLD,&rank);
+
+ MTest_Init(&argc, &argv);
+ MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+ MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (i) {
printf("Can't allocate memory in test program\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
if (i) {
printf("Can't allocate memory in test program\n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
- MPI_Win_create(counter_mem, pof2*2*sizeof(int), sizeof(int),
+ MPI_Win_create(counter_mem, pof2 * 2 * sizeof(int), sizeof(int),
- /* gather the results from other processes, sort them, and check
- whether they represent a counter being incremented by 1 */
+ /* gather the results from other processes, sort them, and check
+ * whether they represent a counter being incremented by 1 */
- MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT,
- 0, MPI_COMM_WORLD);
+ MPI_Gather(MPI_IN_PLACE, 0, MPI_DATATYPE_NULL, results, NTIMES, MPI_INT, 0, MPI_COMM_WORLD);
- qsort(results+NTIMES, NTIMES*(nprocs-1), sizeof(int), compar);
+ qsort(results + NTIMES, NTIMES * (nprocs - 1), sizeof(int), compar);
- get_idx. set idx=acc_idx for next iteration */
- acc_idx[level] = idx + 1;
- get_idx[level] = idx + mask*2;
- idx = idx + 1;
- }
- else {
+ * get_idx. set idx=acc_idx for next iteration */
+ acc_idx[level] = idx + 1;
+ get_idx[level] = idx + mask * 2;
+ idx = idx + 1;
+ }
+ else {
- get_idx. set idx=acc_idx for next iteration */
- acc_idx[level] = idx + mask*2;
- get_idx[level] = idx + 1;
- idx = idx + mask*2;
- }
+ * get_idx. set idx=acc_idx for next iteration */
+ acc_idx[level] = idx + mask * 2;
+ get_idx[level] = idx + 1;
+ idx = idx + mask * 2;
+ }
/* for (i=0; i<nlevels; i++)
printf("Rank %d, acc_idx[%d]=%d, get_idx[%d]=%d\n", rank,
/* for (i=0; i<nlevels; i++)
printf("Rank %d, acc_idx[%d]=%d, get_idx[%d]=%d\n", rank,
- MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
+ MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
- for (i=0; i<NTIMES; i++) {
- Get_nextval_tree(win, get_array, get_type, acc_type,
- nlevels, counter_vals+i);
+ for (i = 0; i < NTIMES; i++) {
+ Get_nextval_tree(win, get_array, get_type, acc_type, nlevels, counter_vals + i);
/* printf("Rank %d, counter %d\n", rank, value); */
}
/* printf("Rank %d, counter %d\n", rank, value); */
}
- /* gather the results to the root */
- MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL,
- 0, MPI_COMM_WORLD);
+ /* gather the results to the root */
+ MPI_Gather(counter_vals, NTIMES, MPI_INT, NULL, 0, MPI_DATATYPE_NULL, 0, MPI_COMM_WORLD);
void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
void Get_nextval_tree(MPI_Win win, int *get_array, MPI_Datatype get_type,
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
MPI_Win_lock(MPI_LOCK_EXCLUSIVE, 0, 0, win);
- MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type,
- MPI_SUM, win);
+ MPI_Accumulate(one, nlevels, MPI_INT, 0, 0, 1, acc_type, MPI_SUM, win);
MPI_Get(get_array, nlevels, MPI_INT, 0, 0, 1, get_type, win);
MPI_Win_unlock(0, win);
*value = localvalue;
MPI_Get(get_array, nlevels, MPI_INT, 0, 0, 1, get_type, win);
MPI_Win_unlock(0, win);
*value = localvalue;