【问题标题】:Can I create a structure for storing data and send it via MPI?我可以创建一个用于存储数据的结构并通过 MPI 发送它吗?
【发布时间】:2015-06-22 19:12:34
【问题描述】:

我尝试并行化运行图像的进程,并且图像进行基本操作。 我正在尝试通过定义如下的 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));                  

【问题讨论】:

    标签: c struct mpi


    【解决方案1】:

    这似乎是正确的。通过调用 MPI_Type_create_struct,您可以创建自定义 MPI 类型。然后调用 MPI_Type_commit 您现在可以使用新类型。通过使用在 MPI_Type_create_struct 函数中创建的句柄。我相信您代码中的句柄是变量 point_type

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

    【讨论】:

      猜你喜欢
      • 2016-01-31
      • 1970-01-01
      • 2021-11-19
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-17
      • 1970-01-01
      相关资源
      最近更新 更多