1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2001 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
7 /* This test checks an oddball case for generalized active target
8 * synchronization where the start occurs before the post. Since start can
9 * block until the corresponding post, the group passed to start must be
10 * disjoint from the group passed to post and processes must avoid a circular
11 * wait. Here, odd/even groups are used to accomplish this and the even group
12 * reverses its start/post calls.
21 int main(int argc, char **argv) {
22 int i, rank, nproc, errors = 0;
27 int odd_nproc, even_nproc;
28 int *odd_ranks, *even_ranks;
29 MPI_Group odd_group, even_group, world_group;
31 MTest_Init(&argc, &argv);
33 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
38 printf("Error: this test requires two or more processes\n");
39 MPI_Abort(MPI_COMM_WORLD, 100);
42 /* Set up odd/even groups and buffers */
44 odd_nproc = nproc / 2;
45 even_nproc = nproc / 2 + ( (nproc % 2 == 0) ? 0 : 1 );
47 odd_ranks = malloc(sizeof(int) * odd_nproc);
48 even_ranks = malloc(sizeof(int) * even_nproc);
50 for (i = 0; i < even_nproc; i++)
53 for (i = 0; i < odd_nproc; i++)
56 MPI_Comm_group(MPI_COMM_WORLD, &world_group);
57 MPI_Group_incl(world_group, odd_nproc, odd_ranks, &odd_group);
58 MPI_Group_incl(world_group, even_nproc, even_ranks, &even_group);
60 /* Create the window */
62 MPI_Alloc_mem(nproc*sizeof(int), MPI_INFO_NULL, &win_buf);
64 for (i = 0; i < nproc; i++)
67 MPI_Win_create(win_buf, nproc*sizeof(int), sizeof(int), MPI_INFO_NULL,
68 MPI_COMM_WORLD, &win);
70 /* Perform PSCW communication: Odd/even matchup */
73 MPI_Win_start(odd_group, 0, win); /* Even-numbered procs target odd procs */
74 MPI_Win_post(odd_group, 0, win); /* Even procs are targeted by odd procs */
76 /* Write to my slot at each target */
77 for (i = 0; i < odd_nproc; i++)
78 MPI_Put(&rank, 1, MPI_INT, odd_ranks[i], rank, 1, MPI_INT, win);
81 MPI_Win_post(even_group, 0, win); /* Odd procs are targeted by even procs */
82 MPI_Win_start(even_group, 0, win); /* Odd-numbered procs target even procs */
84 /* Write to my slot at each target */
85 for (i = 0; i < even_nproc; i++)
86 MPI_Put(&rank, 1, MPI_INT, even_ranks[i], rank, 1, MPI_INT, win);
90 MPI_Win_complete(win);
93 /* Perform PSCW communication: Odd/odd and even/even matchup */
96 MPI_Win_post(even_group, 0, win); /* Even procs are targeted by even procs */
97 MPI_Win_start(even_group, 0, win); /* Even-numbered procs target even procs */
99 /* Write to my slot at each target */
100 for (i = 0; i < even_nproc; i++)
101 MPI_Put(&rank, 1, MPI_INT, even_ranks[i], rank, 1, MPI_INT, win);
104 MPI_Win_post(odd_group, 0, win); /* Odd procs are targeted by odd procs */
105 MPI_Win_start(odd_group, 0, win); /* Odd-numbered procs target odd procs */
107 /* Write to my slot at each target */
108 for (i = 0; i < odd_nproc; i++)
109 MPI_Put(&rank, 1, MPI_INT, odd_ranks[i], rank, 1, MPI_INT, win);
113 MPI_Win_complete(win);
116 for (i = 0; i < nproc; i++) {
117 if (win_buf[i] != i) {
120 SQUELCH( printf("%d: Error -- win_buf[%d] = %d, expected %d\n",
121 rank, i, win_buf[i], i);
127 MPI_Free_mem(win_buf);
129 MPI_Group_free(&world_group);
130 MPI_Group_free(&odd_group);
131 MPI_Group_free(&even_group);
136 MTest_Finalize( errors );
138 return MTestReturnValue( errors );