我可以创建一个存储数据的结构并通过 MPI 发送它吗?

标签 c struct mpi

我尝试将运行图像的进程并行化,图像执行基本操作。 我正在尝试通过定义如下的 MPI 发送结构:

像素的结构:

 typedef struct
{       
        unsigned char R;   
        unsigned char G;    
        unsigned char B;    
}pixel;

发送 MPI 的结构 ()

typedef struct     
{   
    pixel *vec; // pixels for process 3 bytes multiply qty     
    int qty; // count datas     
    int aux; // init      
 } Estructura;    

我不熟悉使用 MPI 库在分布式应用程序中运行,我以前使用过它但没有创建结构类型。 我不确定这是否是我应该遵循的程序。

有人可以向我解释如何准备要发送的结构 Estructura 吗?

int lens[4]={1,1,1,1};  
MPI_Aint  disps[4];    
MPI_Datatype oldtypes[3], point_type;   
disps[0] = 0; oldtypes[0] = MPI_UNSIGNED;    
disps[1] = &pixel.G - &pixel; oldtypes[1] = MPI_UNSIGNED;    
disps[2] =  &pixel.B - &pixel.G; oldtypes[2] = MPI_UNSIGNED;   
disps[3] = sizeof(pixel); oldtype[3] = MPI_UB;    
MPI_Type_create_struct(3, lens, disps, oldtypes, &point_type);    
MPI_Type_commit(&point_type);                 

准备接收数据

MPI_Status status;                   
MPI_Probe(source, tag, comm, &status);                
MPI_Get_count(&status, point_type, &column.nz);                   
    if (nz == MPI_UNDEFINED)     
MPI_Recv(Estructura.vec, Estructura.qty, Estructura.aux, point_type, source, tag, comm, MPI_STATUS_IGNORE);                
pixel *tem =(pixel*)malloc(Estructura.qty *sizeof(point));                  

最佳答案

看来是对的。通过调用 MPI_Type_create_struct,您可以创建自定义 MPI 类型。通过调用 MPI_Type_commit,您现在可以使用新类型。通过使用在 MPI_Type_create_struct 函数中创建的句柄。我相信您代码中的句柄是变量 point_type

所以只需调用 MPI_Send(buffer, count, point_type, dest, tag, comm);

关于我可以创建一个存储数据的结构并通过 MPI 发送它吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29673715/

相关文章:

c - 预处理器指令

c - 无法创建新文件

c++ - mpicxx : Incompatible library version

c++ - MPI-并行 HDF5 : H5Pset_fapl_mpio equivalent in C++

c - `write(2)` 到本地文件系统的原子性

c - 结构指针数组的问题

objective-c - 我如何在 Objective-C 中传递(按值)结构?

c - 使用 malloc、结构和可能参数的问题

segmentation-fault - MPI 派生数据类型发送错误 (Fortran)

c - C语言生成文件