Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add MPICH3 rma tests (15 out of 88 should be passing now)
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / pscw_ordering.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2001 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6
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.
13  */
14
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <mpi.h>
18 #include "mpitest.h"
19 #include "squelch.h"
20
21 int main(int argc, char **argv) {
22     int i, rank, nproc, errors = 0;
23
24     int *win_buf;
25     MPI_Win win;
26
27     int odd_nproc, even_nproc;
28     int *odd_ranks, *even_ranks;
29     MPI_Group odd_group, even_group, world_group;
30
31     MTest_Init(&argc, &argv);
32
33     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
35
36     if (nproc < 2) {
37         if (rank == 0)
38             printf("Error: this test requires two or more processes\n");
39         MPI_Abort(MPI_COMM_WORLD, 100);
40     }
41
42     /* Set up odd/even groups and buffers */
43
44     odd_nproc = nproc / 2;
45     even_nproc  = nproc / 2 + ( (nproc % 2 == 0) ? 0 : 1 );
46
47     odd_ranks = malloc(sizeof(int) * odd_nproc);
48     even_ranks = malloc(sizeof(int) * even_nproc);
49
50     for (i = 0; i < even_nproc; i++)
51         even_ranks[i] = i*2;
52
53     for (i = 0; i < odd_nproc; i++)
54         odd_ranks[i] = i*2+1;
55
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);
59
60     /* Create the window */
61
62     MPI_Alloc_mem(nproc*sizeof(int), MPI_INFO_NULL, &win_buf);
63
64     for (i = 0; i < nproc; i++)
65         win_buf[i] = -1;
66
67     MPI_Win_create(win_buf, nproc*sizeof(int), sizeof(int), MPI_INFO_NULL,
68                    MPI_COMM_WORLD, &win);
69
70     /* Perform PSCW communication: Odd/even matchup */
71
72     if (rank % 2 == 0) {
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 */
75
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);
79     }
80     else {
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 */
83
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);
87     }
88
89
90     MPI_Win_complete(win);
91     MPI_Win_wait(win);
92
93     /* Perform PSCW communication: Odd/odd and even/even matchup */
94
95     if (rank % 2 == 0) {
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 */
98
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);
102     }
103     else {
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 */
106
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);
110     }
111
112
113     MPI_Win_complete(win);
114     MPI_Win_wait(win);
115
116     for (i = 0; i < nproc; i++) {
117         if (win_buf[i] != i) {
118             errors++;
119
120             SQUELCH( printf("%d: Error -- win_buf[%d] = %d, expected %d\n",
121                             rank, i, win_buf[i], i);
122                    );
123         }
124     }
125
126     MPI_Win_free(&win);
127     MPI_Free_mem(win_buf);
128
129     MPI_Group_free(&world_group);
130     MPI_Group_free(&odd_group);
131     MPI_Group_free(&even_group);
132
133     free(odd_ranks);
134     free(even_ranks);
135
136     MTest_Finalize( errors );
137     MPI_Finalize();
138     return MTestReturnValue( errors );
139 }