distributed - How to send nested structure using MPI_Datatype in MPI using C -


i trying use mpi_datatype send below structure mpi_send crashes while sending structure. wondering how handle situation. here code have written define new mpi data-type:

   typedef struct     {        double x;        double y;     } vertex;     typedef struct    {         int num_vertices;         vertex vertex[2];    } vertex_list;          mpi_datatype vertextype;         mpi_type_contiguous(2,mpi_double,&vertextype);         mpi_type_commit(&vertextype);        mpi_datatype vertexlisttype;         mpi_datatype typev[3] = {mpi_int, vertextype, mpi_ub};         int blocklenv[3] = {1, 2, 1};         mpi_aint dispv[3];         /* compute displacements of structure components */         mpi_address( vertexl, dispv);         mpi_address( vertexl[0].vertex, dispv+1);         mpi_address(  vertexl+1, dispv+2);         base = dispv[0];          (i=0; <3; i++)          dispv[i] -= base;          /* build datatype describing structure */         mpi_type_struct( 3, blocklenv, dispv, typev, &vertexlisttype);         mpi_type_commit(&vertexlisttype); 

https://docs.google.com/document/d/1oqftx0clkkqx7x91blvgiizs5d9jshhtgskafrgc7hk/edit?hl=en

i'm not sure structs going work way you're intending here, can share experience sending structs mpi_send.

rather creating explicit mpi datatype it's possible send struct since of contents in contiguous piece of memory. trick providing correct size , datatype mpi_send operation.

using structs, here's i've done in past (assuming variable vertex_list list has been defined):

mpi_send(&list, sizeof(vertex_list), mpi_byte, <ranktosendto>, <taginteger>, <comm>); 

so data buffer sent pointer list struct, size of buffer size of vertex_list in bytes , mpi datatype bytes.

on receiving end, need supply vertex_list reference receiving buffer:

vertex_list receivelist; mpi_recv(&receivelist, sizeof(vertex_list), mpi_byte, <rankofsender>, <taginteger>, <comm>, <status>); 

hope helps!


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -