Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
91d9f439cb3fd279d38048801771a2dd30f0f9dc
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / accfence1.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 /*
12 static char MTEST_Descrip[] = "Accumulate/Replace with Fence";
13 */
14
15 int main( int argc, char *argv[] )
16 {
17     int errs = 0, err;
18     int rank, size, source, dest;
19     int minsize = 2, count; 
20     MPI_Comm      comm;
21     MPI_Win       win;
22     MPI_Aint      extent;
23     MTestDatatype sendtype, recvtype;
24
25     MTest_Init( &argc, &argv );
26
27     /* The following illustrates the use of the routines to 
28        run through a selection of communicators and datatypes.
29        Use subsets of these for tests that do not involve combinations 
30        of communicators, datatypes, and counts of datatypes */
31     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
32         if (comm == MPI_COMM_NULL) continue;
33         /* Determine the sender and receiver */
34         MPI_Comm_rank( comm, &rank );
35         MPI_Comm_size( comm, &size );
36         source = 0;
37         dest   = size - 1;
38         
39         for (count = 1; count < 65000; count = count * 2) {
40             while (MTestGetDatatypes( &sendtype, &recvtype, count )) {
41                 /* Make sure that everyone has a recv buffer */
42                 recvtype.InitBuf( &recvtype );
43
44                 MPI_Type_extent( recvtype.datatype, &extent );
45                 MPI_Win_create( recvtype.buf, recvtype.count * extent, 
46                                 (int)extent, MPI_INFO_NULL, comm, &win );
47                 MPI_Win_fence( 0, win );
48                 if (rank == source) {
49                     sendtype.InitBuf( &sendtype );
50
51                     /* To improve reporting of problems about operations, we
52                        change the error handler to errors return */
53                     MPI_Win_set_errhandler( win, MPI_ERRORS_RETURN );
54                     
55                     /* MPI_REPLACE on accumulate is almost the same 
56                        as MPI_Put; the only difference is in the
57                        handling of overlapping accumulate operations,
58                        which are not tested here */
59                     err = MPI_Accumulate( sendtype.buf, sendtype.count, 
60                                           sendtype.datatype, dest, 0, 
61                                           recvtype.count, recvtype.datatype, 
62                                           MPI_REPLACE, win );
63                     if (err) {
64                         errs++;
65                         if (errs < 10) {
66                             printf( "Accumulate types: send %s, recv %s\n",
67                                     MTestGetDatatypeName( &sendtype ),
68                                     MTestGetDatatypeName( &recvtype ) );
69                             MTestPrintError( err );
70                         }
71                     }
72                     err = MPI_Win_fence( 0, win );
73                     if (err) {
74                         errs++;
75                         if (errs < 10) {
76                             MTestPrintError( err );
77                         }
78                     }
79                 }
80                 else if (rank == dest) {
81                     MPI_Win_fence( 0, win );
82                     /* This should have the same effect, in terms of
83                        transfering data, as a send/recv pair */
84                     err = MTestCheckRecv( 0, &recvtype );
85                     if (err) {
86                         errs += err;
87                     }
88                 }
89                 else {
90                     MPI_Win_fence( 0, win );
91                 }
92                 MPI_Win_free( &win );
93                 MTestFreeDatatype( &sendtype );
94                 MTestFreeDatatype( &recvtype );
95             }
96         }
97         MTestFreeComm(&comm);
98     }
99
100     MTest_Finalize( errs );
101     MPI_Finalize();
102     return 0;
103 }