How to use and interpret MPI-IO Error codes?

大兔子大兔子 提交于 2019-12-02 02:56:06

Go one step further. Your error code doesn't mean anything by itself. But, you can feed that code to MPI_Error_string and get something more human readable. I have this function in every MPI-IO code I write:

static void handle_error(int errcode, char *str)
{       
    char msg[MPI_MAX_ERROR_STRING];
    int resultlen;
    MPI_Error_string(errcode, msg, &resultlen);
    fprintf(stderr, "%s: %s\n", str, msg);
    MPI_Abort(MPI_COMM_WORLD, 1);
}

And then define this macro:

#define MPI_CHECK(fn) { int errcode; errcode = (fn);\
     if (errcode != MPI_SUCCESS) handle_error  (errcode, #fn ); }

So I can call routines like this:

CHECK(MPI_File_open(comm, "testfile", 
    MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &file) );
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!