|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2014 by Argonne National Laboratory.
|
|
Packit |
0848f5 |
* See COPYRIGHT in top-level directory.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#include <mpi.h>
|
|
Packit |
0848f5 |
#include <stdio.h>
|
|
Packit |
0848f5 |
#include <assert.h>
|
|
Packit |
0848f5 |
#include "mpitest.h"
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
#define ITER 100
|
|
Packit |
0848f5 |
#define MAX_SIZE 65536
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
int rank, nproc, i;
|
|
Packit |
0848f5 |
int errors = 0, all_errors = 0;
|
|
Packit |
0848f5 |
int *buf = NULL, *winbuf = NULL;
|
|
Packit |
0848f5 |
MPI_Win window;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Init(&argc, &argv);
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
MPI_Comm_size(MPI_COMM_WORLD, &nproc);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (nproc < 2) {
|
|
Packit |
0848f5 |
if (rank == 0)
|
|
Packit |
0848f5 |
printf("Error: must be run with two or more processes\n");
|
|
Packit |
0848f5 |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &buf;;
|
|
Packit |
0848f5 |
MPI_Alloc_mem(MAX_SIZE * sizeof(int), MPI_INFO_NULL, &winbuf);
|
|
Packit |
0848f5 |
MPI_Win_create(winbuf, MAX_SIZE * sizeof(int), sizeof(int), MPI_INFO_NULL,
|
|
Packit |
0848f5 |
MPI_COMM_WORLD, &window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_lock_all(0, window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Test Raccumulate local completion with small data.
|
|
Packit |
0848f5 |
* Small data is always copied to header packet as immediate data. */
|
|
Packit |
0848f5 |
if (rank == 1) {
|
|
Packit |
0848f5 |
for (i = 0; i < ITER; i++) {
|
|
Packit |
0848f5 |
MPI_Request acc_req;
|
|
Packit |
0848f5 |
int val = -1;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
buf[0] = rank * i;
|
|
Packit |
0848f5 |
MPI_Raccumulate(&buf[0], 1, MPI_INT, 0, 0, 1, MPI_INT, MPI_MAX, window, &acc_req);
|
|
Packit |
0848f5 |
MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* reset local buffer to check local completion */
|
|
Packit |
0848f5 |
buf[0] = 0;
|
|
Packit |
0848f5 |
MPI_Win_flush(0, window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Get(&val, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
|
|
Packit |
0848f5 |
MPI_Win_flush(0, window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (val != rank * i) {
|
|
Packit |
0848f5 |
printf("%d - Got %d in small Raccumulate test, expected %d (%d * %d)\n", rank, val,
|
|
Packit |
0848f5 |
rank * i, rank, i);
|
|
Packit |
0848f5 |
errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Test Raccumulate local completion with large data .
|
|
Packit |
0848f5 |
* Large data is not suitable for 1-copy optimization, and always sent out
|
|
Packit |
0848f5 |
* from user buffer. */
|
|
Packit |
0848f5 |
if (rank == 1) {
|
|
Packit |
0848f5 |
for (i = 0; i < ITER; i++) {
|
|
Packit |
0848f5 |
MPI_Request acc_req;
|
|
Packit |
0848f5 |
int val0 = -1, val1 = -1, val2 = -1;
|
|
Packit |
0848f5 |
int j;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* initialize data */
|
|
Packit |
0848f5 |
for (j = 0; j < MAX_SIZE; j++) {
|
|
Packit |
0848f5 |
buf[j] = rank + j + i;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Raccumulate(buf, MAX_SIZE, MPI_INT, 0, 0, MAX_SIZE, MPI_INT, MPI_REPLACE, window,
|
|
Packit |
0848f5 |
&acc_req);
|
|
Packit |
0848f5 |
MPI_Wait(&acc_req, MPI_STATUS_IGNORE);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* reset local buffer to check local completion */
|
|
Packit |
0848f5 |
buf[0] = 0;
|
|
Packit |
0848f5 |
buf[MAX_SIZE - 1] = 0;
|
|
Packit |
0848f5 |
buf[MAX_SIZE / 2] = 0;
|
|
Packit |
0848f5 |
MPI_Win_flush(0, window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* get remote values which are modified in local buffer after wait */
|
|
Packit |
0848f5 |
MPI_Get(&val0, 1, MPI_INT, 0, 0, 1, MPI_INT, window);
|
|
Packit |
0848f5 |
MPI_Get(&val1, 1, MPI_INT, 0, MAX_SIZE - 1, 1, MPI_INT, window);
|
|
Packit |
0848f5 |
MPI_Get(&val2, 1, MPI_INT, 0, MAX_SIZE / 2, 1, MPI_INT, window);
|
|
Packit |
0848f5 |
MPI_Win_flush(0, window);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (val0 != rank + i) {
|
|
Packit |
0848f5 |
printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
|
|
Packit |
0848f5 |
val0, rank + i);
|
|
Packit |
0848f5 |
errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (val1 != rank + MAX_SIZE - 1 + i) {
|
|
Packit |
0848f5 |
printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
|
|
Packit |
0848f5 |
val1, rank + MAX_SIZE - 1 + i);
|
|
Packit |
0848f5 |
errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
if (val2 != rank + MAX_SIZE / 2 + i) {
|
|
Packit |
0848f5 |
printf("%d - Got %d in large Raccumulate test, expected %d\n", rank,
|
|
Packit |
0848f5 |
val2, rank + MAX_SIZE / 2 + i);
|
|
Packit |
0848f5 |
errors++;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_unlock_all(window);
|
|
Packit |
0848f5 |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Win_free(&window);
|
|
Packit |
0848f5 |
if (buf)
|
|
Packit |
0848f5 |
MPI_Free_mem(buf);
|
|
Packit |
0848f5 |
if (winbuf)
|
|
Packit |
0848f5 |
MPI_Free_mem(winbuf);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Reduce(&errors, &all_errors, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
if (rank == 0 && all_errors == 0)
|
|
Packit |
0848f5 |
printf(" No Errors\n");
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MPI_Finalize();
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
return 0;
|
|
Packit |
0848f5 |
}
|