|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; -*- */
|
|
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 <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <string.h>
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* tests various miscellaneous functions. */
|
|
Packit Service |
c5cf8c |
#define VERBOSE 0
|
|
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 |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int buf[1024], amode, flag, mynod, len, i;
|
|
Packit Service |
c5cf8c |
int errs = 0, toterrs;
|
|
Packit Service |
c5cf8c |
MPI_File fh;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
MPI_Datatype newtype;
|
|
Packit Service |
c5cf8c |
MPI_Offset disp, offset;
|
|
Packit Service |
c5cf8c |
MPI_Group group;
|
|
Packit Service |
c5cf8c |
MPI_Datatype etype, filetype;
|
|
Packit Service |
c5cf8c |
char datarep[25], *filename;
|
|
Packit Service |
c5cf8c |
int errcode = 0;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
|
|
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: misc -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 |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_open(MPI_COMM_WORLD, filename,
|
|
Packit Service |
c5cf8c |
MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_open");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_write(fh, buf, 1024, MPI_INT, &status);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_write");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_sync(fh);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_sync");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_amode(fh, &amode);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_amode");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_get_amode\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
if (amode != (MPI_MODE_CREATE | MPI_MODE_RDWR)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "amode is %d, should be %d\n\n", amode, MPI_MODE_CREATE | MPI_MODE_RDWR);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_atomicity(fh, &flag;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_atomicity");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (flag) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "atomicity is %d, should be 0\n", flag);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "setting atomic mode\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_set_atomicity(fh, 1);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_set_atomicity");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_atomicity(fh, &flag;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_atomicity");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (!flag) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "atomicity is %d, should be 1\n", flag);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_set_atomicity(fh, 0);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_set_atomicity");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "reverting back to nonatomic mode\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Type_vector(10, 10, 20, MPI_INT, &newtype);
|
|
Packit Service |
c5cf8c |
MPI_Type_commit(&newtype);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_set_view(fh, 1000, MPI_INT, newtype, "native", MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_set_view");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_get_view\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_view(fh, &disp, &etype, &filetype, datarep);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_view");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if ((disp != 1000) || strcmp(datarep, "native")) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "disp = %@LL@, datarep = %s, should be 1000, native\n\n", disp, datarep);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_get_byte_offset\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_byte_offset(fh, 10, &disp;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_byte_offset");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (disp != (1000 + 20 * sizeof(int))) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "byte offset = %@LL@, should be %d\n\n",
|
|
Packit Service |
c5cf8c |
disp, (int) (1000 + 20 * sizeof(int)));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_group(fh, &group);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_group");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_set_size\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_set_size(fh, 1000 + 15 * sizeof(int));
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_set_size");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_sync(fh);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_sync");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_size(fh, &disp;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_size");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (disp != 1000 + 15 * sizeof(int)) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "file size = %@LL@, should be %d\n\n",
|
|
Packit Service |
c5cf8c |
disp, (int) (1000 + 15 * sizeof(int)));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "seeking to eof and testing MPI_File_get_position\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_seek(fh, 0, MPI_SEEK_END);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_seek");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_position(fh, &disp;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_position");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (disp != 10) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "file pointer posn = %@LL@, should be 10\n\n", disp);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_get_byte_offset\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_byte_offset(fh, disp, &offset);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_byte_offset");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (offset != (1000 + 20 * sizeof(int))) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "byte offset = %@LL@, should be %d\n\n",
|
|
Packit Service |
c5cf8c |
offset, (int) (1000 + 20 * sizeof(int)));
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "testing MPI_File_seek with MPI_SEEK_CUR\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_seek(fh, -10, MPI_SEEK_CUR);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_seek");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_position(fh, &disp;;
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_position");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_get_byte_offset(fh, disp, &offset);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_get_byte_offset");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (offset != 1000) {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "file pointer posn in bytes = %@LL@, should be 1000\n\n", offset);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "preallocating disk space up to 8192 bytes\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
errcode = MPI_File_preallocate(fh, 8192);
|
|
Packit Service |
c5cf8c |
if (errcode != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
handle_error(errcode, "MPI_File_Preallocate");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "closing the file and deleting it\n");
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
if (!mynod)
|
|
Packit Service |
c5cf8c |
MPI_File_delete(filename, MPI_INFO_NULL);
|
|
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 |
MPI_Type_free(&newtype);
|
|
Packit Service |
c5cf8c |
MPI_Type_free(&filetype);
|
|
Packit Service |
c5cf8c |
MPI_Group_free(&group);
|
|
Packit Service |
c5cf8c |
free(filename);
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|