Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
This particular RMA test is filled with stupid calls... We send errors for most of...
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / transpose2.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 /* transposes a matrix using put, fence, and derived
11    datatypes. Uses vector and struct (Example 3.33 from MPI 1.1
12    Standard). We could use vector and type_create_resized instead. Run
13    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, A[NROWS][NCOLS], i, j, blocklen[2];
21     MPI_Comm CommDeuce;
22     MPI_Aint disp[2];
23     MPI_Win win;
24     MPI_Datatype column, column1, type[2];
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         if (rank == 0) {
40             for (i = 0; i < NROWS; i++)
41                 for (j = 0; j < NCOLS; j++)
42                     A[i][j] = i * NCOLS + j;
43
44             /* create datatype for one column */
45             MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
46
47             /* create datatype for one column, with the extent of one
48              * integer. we could use type_create_resized instead. */
49             disp[0] = 0;
50             disp[1] = sizeof(int);
51             type[0] = column;
52             type[1] = MPI_UB;
53             blocklen[0] = 1;
54             blocklen[1] = 1;
55             MPI_Type_struct(2, blocklen, disp, type, &column1);
56             MPI_Type_commit(&column1);
57
58             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
59
60             MPI_Win_fence(0, win);
61
62             MPI_Put(A, NROWS * NCOLS, MPI_INT, 1, 0, NCOLS, column1, win);
63
64             MPI_Type_free(&column);
65             MPI_Type_free(&column1);
66
67             MPI_Win_fence(0, win);
68         }
69         else {  /* rank=1 */
70             for (i = 0; i < NROWS; i++)
71                 for (j = 0; j < NCOLS; j++)
72                     A[i][j] = -1;
73             MPI_Win_create(A, NROWS * NCOLS * sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce,
74                            &win);
75             MPI_Win_fence(0, win);
76
77             MPI_Win_fence(0, win);
78
79             for (j = 0; j < NCOLS; j++) {
80                 for (i = 0; i < NROWS; i++) {
81                     if (A[j][i] != i * NCOLS + j) {
82                         if (errs < 50) {
83                             printf("Error: A[%d][%d]=%d should be %d\n", j, i,
84                                    A[j][i], i * NCOLS + j);
85                         }
86                         errs++;
87                     }
88                 }
89             }
90             if (errs >= 50) {
91                 printf("Total number of errors: %d\n", errs);
92             }
93         }
94         MPI_Win_free(&win);
95     }
96
97     MPI_Comm_free(&CommDeuce);
98     MTest_Finalize(errs);
99     MPI_Finalize();
100     return 0;
101 }