2 * (C) 2006 by Argonne National Laboratory.
3 * See COPYRIGHT in top-level directory.
5 * Portions of this code were written by Intel Corporation.
6 * Copyright (C) 2011-2012 Intel Corporation. Intel provides this material
7 * to Argonne National Laboratory subject to Software Grant and Corporate
8 * Contributor License Agreement dated February 8, 2012.
21 static int errors = 0;
23 int main(int argc, char **argv)
26 twoint_t *data = NULL;
30 MTest_Init(&argc, &argv);
32 MPI_Comm_rank(MPI_COMM_WORLD, &me);
33 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
36 MPI_Alloc_mem(sizeof(twoint_t), MPI_INFO_NULL, &data);
39 MPI_Win_create(data, me == 0 ? sizeof(twoint_t) : 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
40 MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
42 /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0.
43 * The loc is the origin process' rank, and the value is (nproc-me). In
44 * the case of MAXLOC, rank 0 should win and in the case of MINLOC, rank
54 MPI_Win_fence(0, win);
57 mine.val = nproc - me;
58 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MAXLOC, win);
59 MPI_Win_fence(0, win);
61 if (me == 0 && (data->loc != 0 || data->val != nproc)) {
63 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
64 0, nproc, data->loc, data->val);
73 MPI_Win_fence(0, win);
76 mine.val = nproc - me;
77 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
78 MPI_Win_fence(0, win);
80 if (me == 0 && (data->loc != nproc - 1 || data->val != 1)) {
82 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
83 nproc - 1, 1, data->loc, data->val);
86 /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0.
87 * The loc is the origin process' rank, and the value is 1. In both cases,
88 * rank 0 should win because the values are equal and it has the lowest
98 MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
103 MPI_Win_lock(MPI_LOCK_SHARED, 0, MPI_MODE_NOCHECK, win);
104 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MAXLOC, win);
105 MPI_Win_unlock(0, win);
107 MPI_Barrier(MPI_COMM_WORLD);
109 if (me == 0 && (data->loc != 0 || data->val != 1)) {
111 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
112 0, 1, data->loc, data->val);
114 MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
122 MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
127 MPI_Win_lock(MPI_LOCK_SHARED, 0, MPI_MODE_NOCHECK, win);
128 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
129 MPI_Win_unlock(0, win);
131 MPI_Barrier(MPI_COMM_WORLD);
133 if (me == 0 && (data->loc != 0 || data->val != 1)) {
135 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
136 0, 1, data->loc, data->val);
145 MTest_Finalize(errors);