MPI - убедитесь, что значение переменной остается в процессе - PullRequest
0 голосов
/ 16 марта 2019

Я хочу отсортировать вектор с помощью mpi.Используемый код выглядит следующим образом:

//here a sort lambda function   

auto sort = [](auto begin, auto end){
  ...........................
};

//Entering the main
int main(int argc, char* argv[]) {

  std::vector<int> vec(SIZE);
  random_vector(begin(vec), end(vec)); // a vector with random values
  auto incre;
  auto begin = vec.begin(), end = vec.begin + incre;


  int my_rank; /* rank of the process     */
  int p;       /* number of processes  */
  int source;  /* source's rank   */
  int dest;    /* destination's rank     */
  int tag = 0; /*  just a tag*/
  MPI_Status status;

  /* Initialisation  */
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &p);

  incre = SIZE / p;

  if (my_rank != 0) {

    dest = 0; 
    sort_function(begin, end);
    MPI_Send(begin, begin + SIZE / p, MPI_INT, dest, tag, MPI_COMM_WORLD);

    /* want to do this but this cannot be done */
    begin = end;
    end += incre;
    /*******************************************/

  } 
  else {
    for (source = 1; source < p; source++) {
      MPI_Recv(vec.begin(), SIZE, MPI_INT, source, tag, MPI_COMM_WORLD, &status); 
    }
  }

  MPI_Finalize();
  return 0;
}

Поэтому мой вопрос заключается в том, как я могу передать другому процессу «начало» и «конец», чтобы они использовали их для продолжения работы (сортировка вектора).

Я хочу, чтобы каждый процесс работал на части вектора.

...