|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2001 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* tests whether atomicity semantics are satisfied for overlapping accesses
|
|
Packit Service |
c5cf8c |
in atomic mode. The probability of detecting errors is higher if you run
|
|
Packit Service |
c5cf8c |
it on 8 or more processes. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* The file name is taken as a command-line argument. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
static void handle_error(int errcode, const char *str)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
char msg[MPI_MAX_ERROR_STRING];
|
|
Packit Service |
c5cf8c |
int resultlen;
|
|
Packit Service |
c5cf8c |
MPI_Error_string(errcode, msg, &resultlen);
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%s: %s\n", str, msg);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MPI_CHECK(fn) { int errcode; errcode = (fn); if (errcode != MPI_SUCCESS) handle_error(errcode, #fn); }
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define BUFSIZE 10000 /* no. of integers */
|
|
Packit Service |
c5cf8c |
#define VERBOSE 0
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int *writebuf, *readbuf, i, mynod, nprocs, len, err;
|
|
Packit Service |
c5cf8c |
char *filename;
|
|
Packit Service |
c5cf8c |
int errs = 0, toterrs;
|
|
Packit Service |
c5cf8c |
MPI_Datatype newtype;
|
|
Packit Service |
c5cf8c |
MPI_File fh;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
MPI_Info info;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* process 0 takes the file name as a command-line argument and
|
|
Packit Service |
c5cf8c |
broadcasts it to other processes */
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
i = 1;
|
|
Packit Service |
c5cf8c |
while ((i < argc) && strcmp("-fname", *argv)) {
|
|
Packit Service |
c5cf8c |
i++;
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (i >= argc) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "\n*# Usage: coll_test -fname filename\n\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
argv++;
|
|
Packit Service |
c5cf8c |
len = strlen(*argv);
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 1);
|
|
Packit Service |
c5cf8c |
strcpy(filename, *argv);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
filename = (char *) malloc(len + 1);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(filename, len + 1, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
writebuf = (int *) malloc(BUFSIZE * sizeof(int));
|
|
Packit Service |
c5cf8c |
readbuf = (int *) malloc(BUFSIZE * sizeof(int));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* test atomicity of contiguous accesses */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* initialize file to all zeros */
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
/* ignore error: file may or may not exist */
|
|
Packit Service |
c5cf8c |
MPI_File_delete(filename, MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_SELF, filename,
|
|
Packit Service |
c5cf8c |
MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
writebuf[i] = 0;
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "\ntesting contiguous accesses\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
writebuf[i] = 10;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
readbuf[i] = 20;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename,
|
|
Packit Service |
c5cf8c |
MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* set atomicity to true */
|
|
Packit Service |
c5cf8c |
err = MPI_File_set_atomicity(fh, 1);
|
|
Packit Service |
c5cf8c |
if (err != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Atomic mode not supported on this file system.\n");
|
|
Packit Service |
c5cf8c |
fflush(stderr);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* process 0 writes and others concurrently read. In atomic mode,
|
|
Packit Service |
c5cf8c |
the data read must be either all old values or all new values; nothing
|
|
Packit Service |
c5cf8c |
in between. */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status));
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
err = MPI_File_read(fh, readbuf, BUFSIZE, MPI_INT, &status);
|
|
Packit Service |
c5cf8c |
if (err == MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
if (readbuf[0] == 0) { /* the rest must also be 0 */
|
|
Packit Service |
c5cf8c |
for (i = 1; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
if (readbuf[i] != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 0\n", mynod, i,
|
|
Packit Service |
c5cf8c |
readbuf[i]);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else if (readbuf[0] == 10) { /* the rest must also be 10 */
|
|
Packit Service |
c5cf8c |
for (i = 1; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
if (readbuf[i] != 10) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 10\n", mynod, i,
|
|
Packit Service |
c5cf8c |
readbuf[i]);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[0] is %d, should be either 0 or 10\n", mynod,
|
|
Packit Service |
c5cf8c |
readbuf[0]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_close(&fh));
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* repeat the same test with a noncontiguous filetype */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_vector(BUFSIZE, 1, 2, MPI_INT, &newtype);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&newtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Info_create(&info;;
|
|
Packit Service |
c5cf8c |
/* I am setting these info values for testing purposes only. It is
|
|
Packit Service |
c5cf8c |
* better to use the default values in practice. */
|
|
Packit Service |
c5cf8c |
MPI_Info_set(info, "ind_rd_buffer_size", "1209");
|
|
Packit Service |
c5cf8c |
MPI_Info_set(info, "ind_wr_buffer_size", "1107");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_delete(filename, MPI_INFO_NULL));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_SELF, filename,
|
|
Packit Service |
c5cf8c |
MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh));
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
writebuf[i] = 0;
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status));
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "\ntesting noncontiguous accesses\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
writebuf[i] = 10;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
readbuf[i] = 20;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, info, &fh));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_set_atomicity(fh, 1));
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", info));
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!mynod) {
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_write(fh, writebuf, BUFSIZE, MPI_INT, &status));
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
err = MPI_File_read(fh, readbuf, BUFSIZE, MPI_INT, &status);
|
|
Packit Service |
c5cf8c |
if (err == MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
if (readbuf[0] == 0) {
|
|
Packit Service |
c5cf8c |
for (i = 1; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
if (readbuf[i] != 0) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 0\n", mynod, i,
|
|
Packit Service |
c5cf8c |
readbuf[i]);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else if (readbuf[0] == 10) {
|
|
Packit Service |
c5cf8c |
for (i = 1; i < BUFSIZE; i++)
|
|
Packit Service |
c5cf8c |
if (readbuf[i] != 10) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[%d] is %d, should be 10\n", mynod, i,
|
|
Packit Service |
c5cf8c |
readbuf[i]);
|
|
Packit Service |
c5cf8c |
goto fn_exit;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Process %d: readbuf[0] is %d, should be either 0 or 10\n", mynod,
|
|
Packit Service |
c5cf8c |
readbuf[0]);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&newtype);
|
|
Packit Service |
c5cf8c |
MPI_Info_free(&info;;
|
|
Packit Service |
c5cf8c |
fn_exit:
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Allreduce(&errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
if (mynod == 0) {
|
|
Packit Service |
c5cf8c |
if (toterrs > 0) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Found %d errors\n", toterrs);
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
fprintf(stdout, " No Errors\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
free(writebuf);
|
|
Packit Service |
c5cf8c |
free(readbuf);
|
|
Packit Service |
c5cf8c |
free(filename);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|