|
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 |
/* many calls are deliberately passed bogus values, are expected to fail, and
|
|
Packit Service |
c5cf8c |
* then checked to see if we get the right error message. Other
|
|
Packit Service |
c5cf8c |
* calls are expected to succeed but the preciese return string is not checked. This
|
|
Packit Service |
c5cf8c |
* rouine and MPI_CHECK macro handle these unexpected error cases */
|
|
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 VERBOSE 0
|
|
Packit Service |
c5cf8c |
/* tests if error message is printed correctly */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char **argv)
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int i, rank, len, err;
|
|
Packit Service |
c5cf8c |
int errs = 0;
|
|
Packit Service |
c5cf8c |
char *filename, *tmp;
|
|
Packit Service |
c5cf8c |
MPI_File fh;
|
|
Packit Service |
c5cf8c |
char string[MPI_MAX_ERROR_STRING];
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
if (!rank) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Tests if errors are reported correctly...\n");
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Should say \"Invalid displacement argument\"\n\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
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 (!rank) {
|
|
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: simple -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 + 10);
|
|
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 + 10, 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 + 10);
|
|
Packit Service |
c5cf8c |
MPI_Bcast(filename, len + 10, MPI_CHAR, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* each process opens a separate file called filename.'myrank' */
|
|
Packit Service |
c5cf8c |
tmp = (char *) malloc(len + 10);
|
|
Packit Service |
c5cf8c |
strcpy(tmp, filename);
|
|
Packit Service |
c5cf8c |
sprintf(filename, "%s.%d", tmp, rank);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_CHECK(MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE + MPI_MODE_RDWR,
|
|
Packit Service |
c5cf8c |
MPI_INFO_NULL, &fh));
|
|
Packit Service |
c5cf8c |
err = MPI_File_set_view(fh, -1, MPI_BYTE, MPI_BYTE, "native", MPI_INFO_NULL);
|
|
Packit Service |
c5cf8c |
/* disp is deliberately passed as -1 */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* This test is designed for ROMIO specifically and tests for a
|
|
Packit Service |
c5cf8c |
* specific error message */
|
|
Packit Service |
c5cf8c |
if (err != MPI_SUCCESS) {
|
|
Packit Service |
c5cf8c |
MPI_Error_string(err, string, &len;;
|
|
Packit Service |
c5cf8c |
if (!rank) {
|
|
Packit Service |
c5cf8c |
#if VERBOSE
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "%s\n", string);
|
|
Packit Service |
c5cf8c |
#else
|
|
Packit Service |
c5cf8c |
/* check for the word "displacement" in the message.
|
|
Packit Service |
c5cf8c |
* This allows other formatting of the message */
|
|
Packit Service |
c5cf8c |
if (strstr(string, "displacement") == 0) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unexpected error message %s\n", string);
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
errs++;
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "File set view did not return an error\n");
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_File_close(&fh;;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
free(filename);
|
|
Packit Service |
c5cf8c |
free(tmp);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (!rank) {
|
|
Packit Service |
c5cf8c |
if (errs == 0) {
|
|
Packit Service |
c5cf8c |
printf(" No Errors\n");
|
|
Packit Service |
c5cf8c |
} else {
|
|
Packit Service |
c5cf8c |
printf(" Found %d errors\n", errs);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|