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) {
25 twoint_t *data = NULL;
29 MTest_Init(&argc, &argv);
31 MPI_Comm_rank(MPI_COMM_WORLD, &me);
32 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
35 MPI_Alloc_mem(sizeof(twoint_t), MPI_INFO_NULL, &data);
38 MPI_Win_create(data, me == 0 ? sizeof(twoint_t) : 0, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
39 MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
41 /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0.
42 * The loc is the origin process' rank, and the value is (nproc-me). In
43 * the case of MAXLOC, rank 0 should win and in the case of MINLOC, rank
53 MPI_Win_fence(0, win);
56 mine.val = nproc - me;
57 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MAXLOC, win);
58 MPI_Win_fence(0, win);
60 if (me == 0 && (data->loc != 0 || data->val != nproc)) {
62 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
63 0, nproc, data->loc, data->val);
72 MPI_Win_fence(0, win);
75 mine.val = nproc - me;
76 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
77 MPI_Win_fence(0, win);
79 if (me == 0 && (data->loc != nproc-1 || data->val != 1)) {
81 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
82 nproc-1, 1, data->loc, data->val);
85 /* All processes perform MAXLOC and MINLOC operations on a 2INT on rank 0.
86 * The loc is the origin process' rank, and the value is 1. In both cases,
87 * rank 0 should win because the values are equal and it has the lowest
97 MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
102 MPI_Win_lock(MPI_LOCK_SHARED, 0, MPI_MODE_NOCHECK, win);
103 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MAXLOC, win);
104 MPI_Win_unlock(0, win);
106 MPI_Barrier(MPI_COMM_WORLD);
108 if (me == 0 && (data->loc != 0 || data->val != 1)) {
110 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
111 0, 1, data->loc, data->val);
113 MPI_Win_fence(MPI_MODE_NOPRECEDE, win);
121 MPI_Win_fence(MPI_MODE_NOSUCCEED, win);
126 MPI_Win_lock(MPI_LOCK_SHARED, 0, MPI_MODE_NOCHECK, win);
127 MPI_Accumulate(&mine, 1, MPI_2INT, 0, 0, 1, MPI_2INT, MPI_MINLOC, win);
128 MPI_Win_unlock(0, win);
130 MPI_Barrier(MPI_COMM_WORLD);
132 if (me == 0 && (data->loc != 0 || data->val != 1)) {
134 printf("Expected: { loc = %d, val = %d } Actual: { loc = %d, val = %d }\n",
135 0, 1, data->loc, data->val);
144 MTest_Finalize(errors);