Class 的私有成员的 MPI 操作

MPI operations on private members of a Class

我想知道您是否可以将 MPI 与 C++ 的私有成员一起使用 类,例如下面示例中的 void bcast

class foo
{
public:
  int rank;
  int size;

  foo()
  { 
   _isOperational = false;
  }

 void bcast(){
    MPI_Bcast(&_isOperational,1,MPI::BOOL, 0, MPI_COMM_WORLD);
  }
private:
  bool _isOperational;

};

我得到的只是一个僵局。这有意义吗?

证明私有成员在 MPI 中不是问题的最小可重现示例。

#include <mpi.h>
#include <stdio.h>


class foo
{
private:
  bool _isOperational;

public:
  int rank;
  int size;

  foo()
  { 
   _isOperational = false;
  }
  void changeOperational(bool b){
    _isOperational = b;
  }

  void printOperational(){
    printf("Rank: %d -> Operational: %d\n",rank,_isOperational);
  }

 void bcast(){
    MPI_Bcast(&_isOperational,1,MPI::BOOL, 0, MPI_COMM_WORLD);
  }

};


int main(){

  foo f;
  MPI_Init(NULL,NULL);

  MPI_Comm_size(MPI_COMM_WORLD, &f.size);
  MPI_Comm_rank(MPI_COMM_WORLD, &f.rank);
  f.printOperational();
  if(f.rank == 0)
    f.changeOperational(true);


  f.bcast();
  f.printOperational();


  MPI_Finalize();



  return 0;
}