fileerrret.c

来自「fortran并行计算包」· C语言 代码 · 共 76 行

C
76
字号
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * *  (C) 2006 by Argonne National Laboratory. *      See COPYRIGHT in top-level directory. */#include "mpi.h"#include "mpitestconf.h"#include <stdio.h>#ifdef HAVE_STRING_H#include <string.h>#endif#include "mpitest.h"static int verbose = 0;static int ncalls = 0;void efn( MPI_File *fh, int *code, ... );void efn( MPI_File *fh, int *code, ... ){    ncalls ++;    *code = MPI_SUCCESS;}int main( int argc, char *argv[] ){    MPI_File fh;    MPI_Errhandler eh;    char filename[10];    int errs = 0, toterrs, rank, rc;    MPI_Init( &argc, &argv );    /* Test that the default error handler is errors return for files */    strncpy( filename, "t1", sizeof(filename) );    rc = MPI_File_open( MPI_COMM_WORLD, filename, 			MPI_MODE_RDWR, MPI_INFO_NULL, &fh );    if (!rc) {	errs++;	printf( "Did not get error from open for writing without CREATE\n" );    }    /* Test that we can change the default error handler by changing       the error handler on MPI_FILE_NULL. */    MPI_File_create_errhandler( efn, &eh );    MPI_File_set_errhandler( MPI_FILE_NULL, eh );    rc = MPI_File_open(MPI_COMM_WORLD, filename, 		       MPI_MODE_RDWR, MPI_INFO_NULL, &fh );    if (rc) {	printf( "Returned error from open (should have called error handler instead)\n");    }    if (ncalls != 1) {	errs++;	printf( "Did not invoke error handler when opening a non-existent file for writing and reading (without MODE_CREATE)\n" );    }        /* Find out how many errors we saw */    MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );    MPI_Comm_rank( MPI_COMM_WORLD, &rank );    if (rank == 0) {	if (toterrs == 0) {	    printf( " No Errors\n" );	}	else {	    printf( " Saw %d errors\n", toterrs );	}    }    MPI_Finalize();    return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?