File: error.c

package info (click to toggle)
openmpi 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 99,912 kB
  • ctags: 55,589
  • sloc: ansic: 525,999; f90: 18,307; makefile: 12,062; sh: 6,583; java: 6,278; asm: 3,515; cpp: 2,227; perl: 2,136; python: 1,350; lex: 734; fortran: 52; tcl: 12
file content (106 lines) | stat: -rw-r--r-- 2,671 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
/*
 *  (C) 2001 by Argonne National Laboratory.
 *      See COPYRIGHT in top-level directory.
 */
#include "mpi.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define VERBOSE 0
/* tests if error message is printed correctly */

int main(int argc, char **argv)
{
    int i, rank, len, err;
    int errs = 0;
    char *filename, *tmp;
    MPI_File fh;
    char string[MPI_MAX_ERROR_STRING];

    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

#if VERBOSE
    if (!rank) {
	fprintf(stderr, "Tests if errors are reported correctly...\n");
	fprintf(stderr, "Should say \"Invalid displacement argument\"\n\n");
    }
#endif

/* process 0 takes the file name as a command-line argument and
   broadcasts it to other processes */
    if (!rank) {
	i = 1;
	while ((i < argc) && strcmp("-fname", *argv)) {
	    i++;
	    argv++;
	}
	if (i >= argc) {
	    fprintf(stderr, "\n*#  Usage: simple -fname filename\n\n");
	    MPI_Abort(MPI_COMM_WORLD, 1);
	}
	argv++;
	len = strlen(*argv);
	filename = (char *) malloc(len+10);
	strcpy(filename, *argv);
	MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
	MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
    }
    else {
	MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD);
	filename = (char *) malloc(len+10);
	MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD);
    }

    /* each process opens a separate file called filename.'myrank' */
    tmp = (char *) malloc(len+10);
    strcpy(tmp, filename);
    sprintf(filename, "%s.%d", tmp, rank);

    err = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE+MPI_MODE_RDWR,
		        MPI_INFO_NULL, &fh);
    err = MPI_File_set_view(fh, -1, MPI_BYTE, MPI_BYTE, "native",
                            MPI_INFO_NULL);
    /* disp is deliberately passed as -1 */

    /* This test is designed for ROMIO specifically and tests for a
       specific error message */
    if (err != MPI_SUCCESS) {
	MPI_Error_string(err, string, &len);
	if (!rank) {
#if VERBOSE
	    fprintf(stderr, "%s\n", string);
#else
	    /* check for the word "displacement" in the message.
	       This allows other formatting of the message */
	    if (strstr( string, "displacement" ) == 0) {
		fprintf( stderr, "Unexpected error message %s\n", string );
		errs++;
	    }
#endif
	}
    }
    else {
	errs++;
	fprintf( stderr, "File set view did not return an error\n" );
    }

    MPI_File_close(&fh);

    free(filename);
    free(tmp);

    if (!rank) {
	if (errs == 0) {
	    printf( " No Errors\n" );
	}
	else {
	    printf( " Found %d errors\n", errs );
	}
    }

    MPI_Finalize();
    return 0;
}