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 / transpose6.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
10 /* This does a local transpose-cum-accumulate operation. Uses
11    vector and hvector datatypes (Example 3.32 from MPI 1.1
12    Standard). Run on 1 process. */
13
14 #define NROWS 100
15 #define NCOLS 100
16
17 int main(int argc, char *argv[])
18 {
19     int rank, nprocs, A[NROWS][NCOLS], B[NROWS][NCOLS], i, j;
20     MPI_Win win;
21     MPI_Datatype column, xpose;
22     int errs = 0;
23
24     MTest_Init(&argc, &argv);
25     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
26     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
27
28     if (rank == 0) {
29         for (i = 0; i < NROWS; i++)
30             for (j = 0; j < NCOLS; j++)
31                 A[i][j] = B[i][j] = i * NCOLS + j;
32
33         /* create datatype for one column */
34         MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
35         /* create datatype for matrix in column-major order */
36         MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
37         MPI_Type_commit(&xpose);
38
39         MPI_Win_create(B, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF,
40                        &win);
41
42         MPI_Win_fence(0, win);
43
44         MPI_Accumulate(A, NROWS * NCOLS, MPI_INT, 0, 0, 1, xpose, MPI_SUM, win);
45
46         MPI_Type_free(&column);
47         MPI_Type_free(&xpose);
48
49         MPI_Win_fence(0, win);
50
51         for (j = 0; j < NCOLS; j++) {
52             for (i = 0; i < NROWS; i++) {
53                 if (B[j][i] != i * NCOLS + j + j * NCOLS + i) {
54                     if (errs < 20) {
55                         printf("Error: B[%d][%d]=%d should be %d\n", j, i,
56                                B[j][i], i * NCOLS + j + j * NCOLS + i);
57                     }
58                     errs++;
59                 }
60             }
61         }
62         if (errs >= 20) {
63             printf("Total number of errors: %d\n", errs);
64         }
65
66         MPI_Win_free(&win);
67     }
68     MTest_Finalize(errs);
69     MPI_Finalize();
70     return 0;
71 }