MPI_Type_get_extent发生错误

时间:2016-10-14 10:28:02

标签: c++ mpi c++14 openmpi

当我执行mpirun -n 2 ./out时,我无法在以下代码中扩展派生的MPI数据类型。为什么呢?

错误讯息:

*** An error occurred in MPI_Type_get_extent
*** reported by process [969080833,1]
*** on communicator MPI_COMM_WORLD
*** MPI_ERR_ARG: invalid argument of some other kind
*** MPI_ERRORS_ARE_FATAL (processes in this communicator will now abort,
***    and potentially your MPI job)
1 more process has sent help message help-mpi-errors.txt / mpi_errors_are_fatal
Set MCA parameter "orte_base_help_aggregate" to 0 to see all help / error messages

main.cpp中:

#include "mpi.h"

MPI_Datatype MPI_A;

struct A
{ 
    int a;
};  

int main()
{   
    MPI_Init(NULL, NULL);

    A a;

    int nblock = 1;
    int block_count = 1;
    MPI_Aint offset = 0;
    MPI_Datatype block_type = MPI_INT;

    MPI_Type_struct(nblock, &block_count, &offset, &block_type, &MPI_A);
    MPI_Type_commit(&MPI_A);

    MPI_Aint extent;
    MPI_Type_get_extent(MPI_A, NULL, &extent);

    return 0;
}

1 个答案:

答案 0 :(得分:2)

错误在于:

MPI_Type_get_extent(MPI_A, NULL, &extent);
                           ^^^^

MPI_Type_get_extent调用中的下限和范围参数都不能是NULL

此外,您的代码缺少对MPI_Finalize()强制性调用。