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 / transpose5.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 <stdlib.h>
9 #include "mpitest.h"
10
11 /* This does a transpose-cum-accumulate operation. Uses  vector and
12    hvector datatypes (Example 3.32 from MPI 1.1 Standard). Run on 2
13    processes */
14
15 #define NROWS 1000
16 #define NCOLS 1000
17
18 int main(int argc, char *argv[])
19 {
20     int rank, nprocs, **A, *A_data, i, j;
21     MPI_Comm CommDeuce;
22     MPI_Win win;
23     MPI_Datatype column, xpose;
24     int errs = 0;
25
26     MTest_Init(&argc, &argv);
27     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29
30     if (nprocs < 2) {
31         printf("Run this program with 2 or more processes\n");
32         MPI_Abort(MPI_COMM_WORLD, 1);
33     }
34
35     MPI_Comm_split(MPI_COMM_WORLD, (rank < 2), rank, &CommDeuce);
36
37     if (rank < 2) {
38         A_data = (int *) malloc(NROWS * NCOLS * sizeof(int));
39         A = (int **) malloc(NROWS * sizeof(int *));
40
41         A[0] = A_data;
42         for (i = 1; i < NROWS; i++)
43             A[i] = A[i - 1] + NCOLS;
44
45         if (rank == 0) {
46             for (i = 0; i < NROWS; i++)
47                 for (j = 0; j < NCOLS; j++)
48                     A[i][j] = i * NCOLS + j;
49
50             /* create datatype for one column */
51             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
52             /* create datatype for matrix in column-major order */
53             MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
54             MPI_Type_commit(&xpose);
55
56             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
57
58             MPI_Win_fence(0, win);
59
60             MPI_Accumulate(&A[0][0], NROWS * NCOLS, MPI_INT, 1, 0, 1, xpose, MPI_SUM, win);
61
62             MPI_Type_free(&column);
63             MPI_Type_free(&xpose);
64
65             MPI_Win_fence(0, win);
66         }
67         else {  /* rank=1 */
68             for (i = 0; i < NROWS; i++)
69                 for (j = 0; j < NCOLS; j++)
70                     A[i][j] = i * NCOLS + j;
71             MPI_Win_create(&A[0][0], NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL,
72                            CommDeuce, &win);
73             MPI_Win_fence(0, win);
74
75             MPI_Win_fence(0, win);
76
77             for (j = 0; j < NCOLS; j++) {
78                 for (i = 0; i < NROWS; i++) {
79                     if (A[j][i] != i * NCOLS + j + j * NCOLS + i) {
80                         if (errs < 50) {
81                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
82                                    A[j][i], i * NCOLS + j + j * NCOLS + i);
83                         }
84                         errs++;
85                     }
86                 }
87             }
88             if (errs >= 50) {
89                 printf("Total number of errors: %d\n", errs);
90             }
91         }
92
93         MPI_Win_free(&win);
94
95         free(A_data);
96         free(A);
97
98     }
99
100     MPI_Comm_free(&CommDeuce);
101     MTest_Finalize(errs);
102     MPI_Finalize();
103     return 0;
104 }