Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://github.com/mpoquet/simgrid
[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     {
30         for (i=0; i<NROWS; i++)
31             for (j=0; j<NCOLS; j++)
32                 A[i][j] = B[i][j] = i*NCOLS + j;
33         
34         /* create datatype for one column */
35         MPI_Type_vector(NROWS, 1, NCOLS, MPI_INT, &column);
36         /* create datatype for matrix in column-major order */
37         MPI_Type_hvector(NCOLS, 1, sizeof(int), column, &xpose);
38         MPI_Type_commit(&xpose);
39         
40         MPI_Win_create(B, NROWS*NCOLS*sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_SELF, &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         {
53             for (i=0; i<NROWS; i++)
54            {
55                 if (B[j][i] != i*NCOLS + j + j*NCOLS + i)
56                {
57                 if (errs < 20)
58                 {
59                     printf("Error: B[%d][%d]=%d should be %d\n", j, i,
60                         B[j][i], i*NCOLS + j + j*NCOLS + i);
61                 }
62                     errs++;
63                 }
64            }
65         }
66         if (errs >= 20)
67         {
68            printf("Total number of errors: %d\n", errs);
69         }
70  
71         MPI_Win_free(&win); 
72     }
73     MTest_Finalize(errs);
74     MPI_Finalize(); 
75     return 0; 
76