Search code examples
c++structmpiuser-defined-typesmpich

define an MPI struct with ordering operator < in C++


I have a structure for a serialized program that I want to parallelize with MPI. I'm using MPICH. My program uses the < operator on the sturct to create a map of ids to vertices, so to be able to create the same kind of map I need to keep this operator in my struct.

struct Vertex{
  int id;
  int degree;
  double credit;
  bool operator <(const Vertex& x) {return this->id < x.id;}
};

I need to know how to redefine this struct with an MPI datatype. So far I have this...

  MPI_Datatype vertex_type, oldtypes[3];
  int blockcounts[4];
  MPI_Aint offsets[4], extent_int, extent_double,
                       lower_bound_int, lower_bound_double;

  offsets[0] = 0;
  oldtypes[0] = MPI_INT;
  blockcounts[1] = 1;

  MPI_Type_get_extent(MPI_INT, &lower_bound_int, &extent_int);
  offsets[1] = extent_int;
  oldtypes[1] = MPI_INT;
  blockcounts[1] = 1;

  offsets[2] = 2*extent_int;
  oldtypes[2] = MPI_DOUBLE;
  blockcounts[2] = 1;

  MPI_Type_get_extent(MPI_DOUBLE, &lower_bound_double, &extent_double);
  offsets[3] = 2*extent_int + extent_double;
  oldtypes[3] = MPI_Aint;
  blockcounts[3] = 1;

  MPI_Type_create_struct(4, blockcounts, offsets, oldtypes, &vertex_type);
  MPI_Type_commit(&person_type);

I don't think this is the right way to define an operator in a MPI struct. I've looked for documentation about this, but haven't been able to find anything useful.

https://linux.die.net/man/3/mpi_double https://www.rc.colorado.edu/sites/default/files/Datatypes.pdf

Is there a way that I can give my MPI structure a pointer to the Vertex < operator?


Solution

  • My question is invalid. There's no need to pass an operator in MPI because MPI is concerned with passing data, not functions.

    Thanks for your comments.