Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix+activate rma test
[simgrid.git] / teshsuite / smpi / mpich3-test / rma / win_shared_noncontig.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2012 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <assert.h>
11 #include <mpi.h>
12 #include "mpitest.h"
13
14 #define ELEM_PER_PROC 10000
15
16 const int verbose = 0;
17
18 int main(int argc, char **argv)
19 {
20     int i, j, rank, nproc;
21     int shm_rank, shm_nproc;
22     MPI_Info alloc_shared_info;
23     int errors = 0, all_errors = 0;
24     int disp_unit;
25     int *my_base;
26     MPI_Win shm_win;
27     MPI_Comm shm_comm;
28
29     MPI_Init(&argc, &argv);
30
31     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
32     MPI_Comm_size(MPI_COMM_WORLD, &nproc);
33
34     MPI_Info_create(&alloc_shared_info);
35     MPI_Info_set(alloc_shared_info, "alloc_shared_noncontig", "true");
36
37     MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, rank, MPI_INFO_NULL, &shm_comm);
38
39     MPI_Comm_rank(shm_comm, &shm_rank);
40     MPI_Comm_size(shm_comm, &shm_nproc);
41
42     /* Allocate ELEM_PER_PROC integers for each process */
43     MPI_Win_allocate_shared(sizeof(int) * ELEM_PER_PROC, sizeof(int), alloc_shared_info,
44                             shm_comm, &my_base, &shm_win);
45
46     MPI_Win_lock_all(MPI_MODE_NOCHECK, shm_win);
47
48     /* Write to all my data */
49     for (i = 0; i < ELEM_PER_PROC; i++) {
50         my_base[i] = i;
51     }
52
53     MPI_Win_sync(shm_win);
54     MPI_Barrier(shm_comm);
55     MPI_Win_sync(shm_win);
56
57     /* Read and verify everyone's data */
58     for (i = 0; i < shm_nproc; i++) {
59         int *base;
60         MPI_Aint size;
61
62         MPI_Win_shared_query(shm_win, i, &size, &disp_unit, &base);
63         assert(size >= ELEM_PER_PROC * sizeof(int));
64
65         for (j = 0; j < ELEM_PER_PROC; j++) {
66             if (base[j] != j) {
67                 errors++;
68                 printf("%d -- Got %d at rank %d index %d, expected %d\n", shm_rank,
69                        base[j], i, j, j);
70             }
71         }
72     }
73
74     MPI_Win_unlock_all(shm_win);
75     MPI_Win_free(&shm_win);
76     MPI_Comm_free(&shm_comm);
77
78     MPI_Info_free(&alloc_shared_info);
79
80     MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
81
82     if (rank == 0 && all_errors == 0)
83         printf(" No Errors\n");
84
85     MPI_Finalize();
86
87     return 0;
88 }