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 / 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, A[NROWS][NCOLS], 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     {
40         MPI_Comm_group(CommDeuce, &comm_group);
41
42         if (rank == 0)
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             MPI_Win_create(NULL, 0, 1, MPI_INFO_NULL, CommDeuce, &win);
55
56             destrank = 1;
57             MPI_Group_incl(comm_group, 1, &destrank, &group);
58             MPI_Win_start(group, 0, win);
59
60             MPI_Put(A, NROWS*NCOLS, MPI_INT, 1, 0, 1, xpose, win);
61
62             MPI_Type_free(&column);
63             MPI_Type_free(&xpose);
64
65             MPI_Win_complete(win);
66         }
67         else
68         { /* rank=1 */
69             for (i=0; i<NROWS; i++)
70                 for (j=0; j<NCOLS; j++)
71                     A[i][j] = -1;
72             MPI_Win_create(A, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, CommDeuce, &win);
73             destrank = 0;
74             MPI_Group_incl(comm_group, 1, &destrank, &group);
75             MPI_Win_post(group, 0, win);
76             MPI_Win_wait(win);
77
78             for (j=0; j<NCOLS; j++)
79             {
80                 for (i=0; i<NROWS; i++)
81                 {
82                     if (A[j][i] != i*NCOLS + j)
83                     {
84                         if (errs < 50)
85                         {
86                             SQUELCH( printf("Error: A[%d][%d]=%d should be %d\n", j, i,
87                                             A[j][i], i*NCOLS + j); );
88                         }
89                         errs++;
90                     }
91                 }
92             }
93             if (errs >= 50)
94             {
95                 printf("Total number of errors: %d\n", errs);
96             }
97         }
98
99         MPI_Group_free(&group);
100         MPI_Group_free(&comm_group);
101         MPI_Win_free(&win);
102     }
103     MPI_Comm_free(&CommDeuce);
104     MTest_Finalize(errs);
105     MPI_Finalize(); 
106     return 0; 
107