vendredi 25 juin 2021

I don't understand how to create structs data type for MPI

I'm trying to create a MPI_datatype of a struct that looks like this:

struct Body{
      double X;
      double Y;
      double Z;
      double Vx;
      double Vy;
      double Vz;
      double Ax;
      double Ay;
      double Az;
      bool mine;
      int S;
    };

I searched online hot to do it and found some examples. On the man page ( https://www.open-mpi.org/doc/v3.0/man3/MPI_Type_struct.3.php ) of MPI_Type_struct it says that C++ is deprecated, and that I should use MPI_Type_create_struct. Then man page of MPI_Type_create_struct ( https://www.open-mpi.org/doc/v3.0/man3/MPI_Type_create_struct.3.php ). I saw an example of someone creating a data type with MPI_Type_create_struct ( Trouble Understanding MPI_Type_create_struct ). But in here he says that you have to resize the data type and does some weird things with foo, &lb, and &extend that I don't understand. Inc the end, someone said that resize dint make much sense and that MPI_Type_create_resized should be used.

My version of the code is

  Body MPI;
  int count=11;
  const int array_of_blocklengths[11] = {1,1,1,1,1,1,1,1,1,1,1};
  MPI_Aint array_of_displacements[11]={16,16,16,16,16,16,16,16,16,1,8};
  MPI_Datatype array_of_types[3] = {MPI_DOUBLE, MPI_C_BOOL, MPI_INT};
  MPI_Datatype tmp_type, MPI_BODY;
  MPI_Aint lb, extent;
  MPI_Type_create_struct(count, array_of_blocklengths, array_of_displacements, array_of_types, &tmp_type);
  MPI_Type_get_extent(tmp_type, &lb, &extent);
  MPI_Type_create_resized(tmp_type, lb, extent, &MPI_BODY);
  MPI_Type_commit(&MPI_BODY);

But this doesn't work and the program explodes when I run it. Compiles fine though.

I would like if someone can explain to me what's the deal with the array_of_displacements, the problem with MPI_Type_get_extent and MPI_Type_create_resized and what should I do to create my data type.

Aucun commentaire:

Enregistrer un commentaire