简体   繁体   English

在C ++中使用排序运算符<定义MPI结构

[英]define an MPI struct with ordering operator < in C++

I have a structure for a serialized program that I want to parallelize with MPI. 我有一个要与MPI并行化的序列化程序的结构。 I'm using MPICH. 我正在使用MPICH。 My program uses the < operator on the sturct to create a map of id s to vertices, so to be able to create the same kind of map I need to keep this operator in my struct. 我的程序使用sturct上的<运算符来创建id到顶点的映射,因此要创建相同类型的映射,我需要将此运算符保留在我的结构中。

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. 我需要知道如何使用MPI数据类型重新定义此结构。 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. 我认为这不是在MPI结构中定义运算符的正确方法。 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 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? 有没有一种方法可以给我的MPI结构一个指向Vertex <运算符的指针?

My question is invalid. 我的问题是无效的。 There's no need to pass an operator in MPI because MPI is concerned with passing data, not functions. 不需要在MPI中传递运算符,因为MPI与传递数据而不是函数有关。

Thanks for your comments. 感谢您的意见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM