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 / acc-pairtype.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2015 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 /* This test is going to test when Accumulate operation is working
9  * with pair types. */
10
11 #include "mpi.h"
12 #include <stdio.h>
13
14 #define DATA_SIZE 25
15
16 typedef struct long_double_int {
17     long double a;
18     int b;
19 } long_double_int_t;
20
21 int main(int argc, char *argv[])
22 {
23     MPI_Win win;
24     int errors = 0;
25     int rank, nproc, i;
26     long_double_int_t *orig_buf;
27     long_double_int_t *tar_buf;
28     MPI_Datatype vector_dtp;
29
30     MPI_Init(&argc, &argv);
31
32     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
33     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
34
35     MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &orig_buf);
36     MPI_Alloc_mem(sizeof(long_double_int_t) * DATA_SIZE, MPI_INFO_NULL, &tar_buf);
37
38     for (i = 0; i < DATA_SIZE; i++) {
39         orig_buf[i].a = 1.0;
40         orig_buf[i].b = 1;
41         tar_buf[i].a = 0;
42         tar_buf[i].b = 0;
43     }
44
45     MPI_Type_vector(5 /* count */ , 3 /* blocklength */ , 5 /* stride */ , MPI_LONG_DOUBLE_INT,
46                     &vector_dtp);
47     MPI_Type_commit(&vector_dtp);
48
49     MPI_Win_create(tar_buf, sizeof(long_double_int_t) * DATA_SIZE, sizeof(long_double_int_t),
50                    MPI_INFO_NULL, MPI_COMM_WORLD, &win);
51
52     if (rank == 0) {
53         MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win);
54         MPI_Accumulate(orig_buf, 1, vector_dtp, 1, 0, 1, vector_dtp, MPI_MAXLOC, win);
55         MPI_Win_unlock(1, win);
56     }
57
58     MPI_Win_free(&win);
59
60     if (rank == 1) {
61         for (i = 0; i < DATA_SIZE; i++) {
62             if (i % 5 < 3) {
63                 if (tar_buf[i].a != 1.0 || tar_buf[i].b != 1) {
64                     errors++;
65                 }
66             }
67             else {
68                 if (tar_buf[i].a != 0.0 || tar_buf[i].b != 0) {
69                     errors++;
70                 }
71             }
72         }
73     }
74
75     MPI_Type_free(&vector_dtp);
76
77     MPI_Free_mem(orig_buf);
78     MPI_Free_mem(tar_buf);
79
80     if (rank == 1) {
81         if (errors == 0)
82             printf(" No Errors\n");
83     }
84
85     MPI_Finalize();
86     return 0;
87 }