[mpich-discuss] custom defined mpi data type

Rajeev Thakur thakur at mcs.anl.gov
Tue Jul 16 02:17:15 CDT 2013


disp[0] should correspond to width, disp[1] to length, …, disp[6] to image_size. The code below has disp[1] for width, disp[6] for buffer_size, and the disp for image_size is missing altogether.

On Jul 15, 2013, at 4:32 PM, Sufeng Niu wrote:

> Hi,
> 
> I try to broadcast a self-defined data type struct, but I found that every time the last value I cannot send it out. ex:
> my data struct is:
> typedef struct image_info_type{
>         int width;
>         int length;
>         int page_num;
>         int buffer_width;
>         int buffer_length;
>         long int buffer_size;
>         long int image_size;
> } image_info_type;
> 
> in my MPI program:
>         ...............
>         int count = 7;
>         MPI_Datatype MPI_Imageinfo;
>         MPI_Datatype types[7] = {MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_INT, MPI_LONG, MPI_LONG};
>         int len[7] = {1, 1, 1, 1, 1, 1, 1};
>         MPI_Aint disp[7];
>         long int base;
>         MPI_Address(image_info, disp);
>         MPI_Address(&(image_info->width), disp+1);
>         MPI_Address(&(image_info->length), disp+2);
>         MPI_Address(&(image_info->page_num), disp+3);
>         MPI_Address(&(image_info->buffer_width), disp+4);
>         MPI_Address(&(image_info->buffer_length), disp+5);
>         MPI_Address(&(image_info->buffer_size), disp+6);
>         base = disp[0];
>         for(i=0; i<7; i++)
>                 disp[i] -= base;
> 
>         MPI_Type_struct(count, len, disp, types, &MPI_Imageinfo);
>         MPI_Type_commit(&MPI_Imageinfo);
>         ...................
> 
> However, when I print out every information on each rank. the image_size is always 0. I cannot figure out anything wrong with my program. I would appreicate that if any one can give any suggestions. Thank you!
> 
> 
> -- 
> Best Regards,
> Sufeng Niu
> ECASP lab, ECE department, Illinois Institute of Technology
> Tel: 312-731-7219
> _______________________________________________
> discuss mailing list     discuss at mpich.org
> To manage subscription options or unsubscribe:
> https://lists.mpich.org/mailman/listinfo/discuss




More information about the discuss mailing list