Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "[TESTS] SMPI/MPICH3: Fix failing rma test"
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / transpose3.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 #include "mpi.h"
7 #include "stdio.h"
8 #include "mpitest.h"
9 #include "squelch.h"
10
11 /* transposes a matrix using post/start/complete/wait and derived
12    datatypes. Uses  vector and hvector (Example 3.32 from MPI 1.1
13    Standard). Run on 2 processes */
14
15 #define NROWS 100
16 #define NCOLS 100
17
18 int main(int argc, char *argv[])
19 {
20     int rank, nprocs, i, j, destrank;
21     MPI_Comm CommDeuce;
22     MPI_Win win;
23     MPI_Datatype column, xpose;
24     MPI_Group comm_group, group;
25     int errs = 0;
26
27     MTest_Init(&argc, &argv);
28     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
29     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30
31     if (nprocs < 2) {
32         printf("Run this program with 2 or more processes\n");
33         MPI_Abort(MPI_COMM_WORLD, 1);
34     }
35
36     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
37
38     if (rank < 2) {
39         MPI_Comm_group(CommDeuce, &comm_group);
40
41         if (rank == 0) {
42             int A[NROWS][NCOLS];
43
44             for (i = 0; i < NROWS; i++)
45                 for (j = 0; j < NCOLS; j++)
46                     A[i][j] = i * NCOLS + j;
47
48             /* create datatype for one column */
49             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
50             /* create datatype for matrix in column-major order */
51             MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
52             MPI_Type_commit(&xpose);
53
54 #ifdef USE_WIN_ALLOCATE
55             int *base_ptr = NULL;
56             MPI_Win_allocate(0, 1, MPI_INFO_NULL, CommDeuce, &base_ptr, &win);
57 #else
58             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
59 #endif
60
61             destrank = 1;
62             MPI_Group_incl(comm_group, 1, &destrank, &group);
63             MPI_Win_start(group, 0, win);
64
65             MPI_Put(A, NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, win);
66
67             MPI_Type_free(&column);
68             MPI_Type_free(&xpose);
69
70             MPI_Win_complete(win);
71         }
72         else {  /* rank=1 */
73             int *A;
74 #ifdef USE_WIN_ALLOCATE
75             MPI_Win_allocate(NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &A,
76                              &win);
77 #else
78             MPI_Alloc_mem(NROWS * NCOLS * sizeof(int), MPI_INFO_NULL, &A);
79             MPI_Win_create(A, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce,
80                            &win);
81 #endif
82             MPI_Win_lock(MPI_LOCK_SHARED, rank, 0, win);
83             for (i = 0; i < NROWS; i++)
84                 for (j = 0; j < NCOLS; j++)
85                     A[i * NCOLS + j] = -1;
86             MPI_Win_unlock(rank, win);
87
88             destrank = 0;
89             MPI_Group_incl(comm_group, 1, &destrank, &group);
90             MPI_Win_post(group, 0, win);
91             MPI_Win_wait(win);
92
93             for (j = 0; j < NCOLS; j++) {
94                 for (i = 0; i < NROWS; i++) {
95                     if (A[j * NROWS + i] != i * NCOLS + j) {
96                         if (errs < 50) {
97                             SQUELCH(printf("Error: A[%d][%d]=%d should be %d\n", j, i,
98                                            A[j * NROWS + i], i * NCOLS + j););
99                         }
100                         errs++;
101                     }
102                 }
103             }
104             if (errs >= 50) {
105                 printf("Total number of errors: %d\n", errs);
106             }
107 #ifndef USE_WIN_ALLOCATE
108             MPI_Free_mem(A);
109 #endif
110         }
111
112         MPI_Group_free(&group);
113         MPI_Group_free(&comm_group);
114         MPI_Win_free(&win);
115     }
116     MPI_Comm_free(&CommDeuce);
117     MTest_Finalize(errs);
118     MPI_Finalize();
119     return 0;
120 }