1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include <mpi.h>
10 #include "mpitest.h"
11
12 #define DATA_NELTS 1000
13 #define NUM_WIN 1000
14 #define DATA_SZ (DATA_NELTS*sizeof(int))
15
main(int argc,char ** argv)16 int main(int argc, char **argv)
17 {
18 int rank, nproc, i;
19 void *base_ptrs[NUM_WIN];
20 MPI_Win window;
21
22 MTest_Init(&argc, &argv);
23
24 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
25 MPI_Comm_size(MPI_COMM_WORLD, &nproc);
26
27 if (rank == 0)
28 MTestPrintfMsg(1, "Starting MPI dynamic window attach test with %d processes\n", nproc);
29
30 MPI_Info info = MPI_INFO_NULL;
31 #ifdef USE_INFO_COLL_ATTACH
32 MPI_Info_create(&info);
33 MPI_Info_set(info, "coll_attach", "true");
34 #endif
35 MPI_Win_create_dynamic(info, MPI_COMM_WORLD, &window);
36 #ifdef USE_INFO_COLL_ATTACH
37 MPI_Info_free(&info);
38 #endif
39
40 for (i = 0; i < NUM_WIN; i++) {
41 MPI_Alloc_mem(DATA_SZ, MPI_INFO_NULL, &base_ptrs[i]);
42 if (rank == 0)
43 MTestPrintfMsg(1, " + Attaching segment %d to window\n", i);
44 MPI_Win_attach(window, base_ptrs[i], DATA_SZ);
45 }
46
47 MPI_Barrier(MPI_COMM_WORLD);
48
49 for (i = 0; i < NUM_WIN; i++) {
50 if (rank == 0)
51 MTestPrintfMsg(1, " + Detaching segment %d to window\n", i);
52 MPI_Win_detach(window, base_ptrs[i]);
53 MPI_Free_mem(base_ptrs[i]);
54 }
55
56 MPI_Win_free(&window);
57 MTest_Finalize(0);
58
59 return 0;
60 }
61