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 / accfence2.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 <stdlib.h>
10 #include "mpitest.h"
11
12 #ifndef MAX_INT
13 #define MAX_INT 0x7fffffff
14 #endif
15
16 /*
17 static char MTEST_Descrip[] = "Test MPI_Accumulate with fence";
18 */
19
20 int main( int argc, char *argv[] )
21 {
22     int errs = 0;
23     int rank, size, source, dest;
24     int minsize = 2, count, i; 
25     MPI_Comm      comm;
26     MPI_Win       win;
27     MPI_Datatype  datatype;
28     int           *winbuf, *sbuf;
29
30     MTest_Init( &argc, &argv );
31
32     /* The following illustrates the use of the routines to 
33        run through a selection of communicators and datatypes.
34        Use subsets of these for tests that do not involve combinations 
35        of communicators, datatypes, and counts of datatypes */
36     while (MTestGetIntracommGeneral( &comm, minsize, 1 )) {
37         if (comm == MPI_COMM_NULL) continue;
38         /* Determine the sender and receiver */
39         MPI_Comm_rank( comm, &rank );
40         MPI_Comm_size( comm, &size );
41         source = 0;
42         dest   = size - 1;
43         
44         for (count = 1; count < 65000; count = count * 2) {
45             datatype = MPI_INT;
46             /* We compare with an integer value that can be as large as
47                size * (count * count + (1/2)*(size-1))
48                For large machines (size large), this can exceed the 
49                maximum integer for some large values of count.  We check
50                that in advance and break this loop if the above value 
51                would exceed MAX_INT.  Specifically,
52
53                size*count*count + (1/2)*size*(size-1) > MAX_INT
54                count*count > (MAX_INT/size - (1/2)*(size-1))
55             */
56             if (count * count > (MAX_INT/size - (size-1)/2)) break;
57             winbuf = (int *)malloc( count * sizeof(int) );
58             sbuf   = (int *)malloc( count * sizeof(int) );
59
60             for (i=0; i<count; i++) winbuf[i] = 0;
61             for (i=0; i<count; i++) sbuf[i] = rank + i * count;
62             MPI_Win_create( winbuf, count * sizeof(int), sizeof(int),
63                             MPI_INFO_NULL, comm, &win );
64             MPI_Win_fence( 0, win );
65             MPI_Accumulate( sbuf, count, MPI_INT, source, 0, count, MPI_INT,
66                                 MPI_SUM, win );
67             MPI_Win_fence( 0, win );
68             if (rank == source) {
69                 /* Check the results */
70                 for (i=0; i<count; i++) {
71                     int result = i * count * size + (size*(size-1))/2;
72                     if (winbuf[i] != result) {
73                         if (errs < 10) {
74                             fprintf( stderr, "Winbuf[%d] = %d, expected %d (count = %d, size = %d)\n",
75                                      i, winbuf[i], result, count, size );
76                         }
77                         errs++;
78                     }
79                 }
80             }
81             free( winbuf );
82             free( sbuf );
83             MPI_Win_free( &win );
84         }
85         MTestFreeComm(&comm);
86     }
87
88     MTest_Finalize( errs );
89     MPI_Finalize();
90     return 0;
91 }