1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
4 * (C) 2003 by Argonne National Laboratory.
5 * See COPYRIGHT in top-level directory.
15 #define MAX_BUF_SIZE (400 * 1024 * 1024) /* 400 MB */
16 #define PUT_SIZE (1024 * 1024) /* 1MB */
19 static char MTEST_Descrip[] = "ADLB mimic test";
24 * This test uses one server process (S), one target process (T)
25 * and a bunch of origin processes (O). 'O' PUTs (LOCK/PUT/UNLOCK)
26 * data to a distinct part of the window, and sends a message to
27 * 'S' once the UNLOCK has completed. The server forwards this
28 * message to 'T'. 'T' GETS the data from this buffer after it
29 * receives the message from 'S', to see if it contains the correct
39 * ------- step 1 -------
45 * ------- SEND -------
49 int main(int argc, char **argv)
51 int comm_size, comm_rank, i, by_rank, errs = 0;
53 char *rma_win_addr, *local_buf;
57 int max_buf_size = 0, put_size = PUT_SIZE;
59 MTest_Init(&argc, &argv);
60 MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
61 MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
64 fprintf(stderr, "This test requires at least 3 processes\n");
65 MPI_Abort(MPI_COMM_WORLD, 1);
68 max_buf_size = comm_size * put_size;
69 if (max_buf_size > MAX_BUF_SIZE) {
70 fprintf(stderr, "Too many processes in COMM_WORLD (max is %d)\n", MAX_BUF_SIZE / put_size);
71 MPI_Abort(MPI_COMM_WORLD, 1);
74 /* If alloc mem returns an error (because too much memory is requested */
75 MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN);
77 rc = MPI_Alloc_mem(max_buf_size, MPI_INFO_NULL, (void *) &rma_win_addr);
79 MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc);
80 MPI_Abort(MPI_COMM_WORLD, 0);
83 memset(rma_win_addr, 0, max_buf_size);
84 MPI_Win_create((void *) rma_win_addr, max_buf_size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
86 /* Note that it is not necessary to use MPI_Alloc_mem for the memory that
87 * is not part of the MPI_Win. */
88 rc = MPI_Alloc_mem(put_size, MPI_INFO_NULL, (void *) &local_buf);
90 MTestPrintErrorMsg("Unable to MPI_Alloc_mem space (not an error)", rc);
91 MPI_Abort(MPI_COMM_WORLD, 0);
94 for (i = 0; i < put_size; i++)
97 MPI_Barrier(MPI_COMM_WORLD);
99 if (comm_rank == 0) { /* target */
100 for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
101 /* Wait for a message from the server to notify me that
102 * someone put some data in my window */
103 MPI_Recv(&by_rank, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, &status);
105 /* Got a message from the server that 'by_rank' put some
106 * data in my local window. Check the last byte to make
107 * sure we got it correctly. */
108 MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
109 MPI_Get((void *) &check, 1, MPI_CHAR, 0,
110 ((by_rank + 1) * put_size) - 1, 1, MPI_CHAR, win);
111 MPI_Win_unlock(0, win);
113 /* If this is not the value I expect, count it as an error */
117 /* Reset the buffer to zero for the next round */
118 memset((void *) (rma_win_addr + (by_rank * put_size)), 0, put_size);
120 /* Tell the origin that I am ready for the next round */
121 MPI_Send(NULL, 0, MPI_INT, by_rank, 0, MPI_COMM_WORLD);
125 else if (comm_rank == 1) { /* server */
126 for (i = 0; i < (NUM_TIMES * (comm_size - 2)); i++) {
127 /* Wait for a message from any of the origin processes
128 * informing me that it has put data to the target
130 MPI_Recv(NULL, 0, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &status);
131 by_rank = status.MPI_SOURCE;
133 /* Tell the target process that it should be seeing some
134 * data in its local buffer */
135 MPI_Send(&by_rank, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
140 for (i = 0; i < NUM_TIMES; i++) {
141 /* Put some data in the target window */
142 MPI_Win_lock(MPI_LOCK_SHARED, 0, 0, win);
143 MPI_Put(local_buf, put_size, MPI_CHAR, 0, comm_rank * put_size,
144 put_size, MPI_CHAR, win);
145 MPI_Win_unlock(0, win);
147 /* Tell the server that the put has completed */
148 MPI_Send(NULL, 0, MPI_INT, 1, 0, MPI_COMM_WORLD);
150 /* Wait for a message from the target that it is ready for
152 MPI_Recv(NULL, 0, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
158 MPI_Free_mem(rma_win_addr);
159 MPI_Free_mem(local_buf);
161 MTest_Finalize(errs);