MPI_Type_get_extent 发生错误

An error occurred in MPI_Type_get_extent

当我执行 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;
}

错误在这里:

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

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

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