gpt4 book ai didi

c - 如何在 C 中定义 MPI 类型数组?

转载 作者:太空宇宙 更新时间:2023-11-04 02:10:50 25 4
gpt4 key购买 nike

我使用下面的代码在 C 中定义了一个大小为 8 并键入 MPI_INTEGER 的数组:

/*=================================================================
C example
=================================================================*/
#include <stdio.h>
#include "mpi.h"

int main(int argc, char** argv){
MPI_FLOAT itype[8];
int nproc;
int iproc;
MPI_Comm icomm;
MPI_Request req;
MPI_Status status;
MPI_Init(&argc,&argv);

icomm = MPI_COMM_WORLD;
MPI_Comm_rank(icomm,&iproc);
MPI_Comm_size(icomm,&nproc);

itype[0] = MPI_FLOAT;
itype[1] = MPI_FLOAT;
itype[2] = MPI_FLOAT;
itype[3] = MPI_FLOAT;
itype[4] = MPI_FLOAT;
itype[5] = MPI_FLOAT;
itype[6] = MPI_FLOAT;
itype[7] = MPI_UB;

MPI_Finalize();

}

我收到了以下错误:

type_derived_struct.c(18): error: expected a ";"
MPI_FLOAT itype[8];
^

type_derived_struct.c(93): error: identifier "itype" is undefined
itype[0] = MPI_FLOAT;

我正在使用英特尔 openmpi。谢谢!

最佳答案

你想要

MPI_Datatype itype[8];     

MPI_DatatypeMPI_FLOAT 的类型(和 MPI_INT 等)

关于c - 如何在 C 中定义 MPI 类型数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14363682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com