From Forensic Peafowl, 5 Months ago, written in Plain Text.
Embed
  1. string alignLoad(string w, int rankInGroup, int sizeGroup) {
  2.     int prev, next;
  3.    
  4.     if (rankInGroup != 0)
  5.         prev = rankInGroup - 1;
  6.     else
  7.         prev = MPI_PROC_NULL;
  8.    
  9.     if (rankInGroup != sizeGroup - 1)
  10.         next = rankInGroup + 1;
  11.     else
  12.         next = MPI_PROC_NULL;
  13.  
  14.     int lNext, lPrev, l;
  15.  
  16.     lNext = l = w.length();
  17.     MPI_Sendrecv(&l, 1, MPI_INT, prev, 0, &lNext, 1, MPI_INT, next, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  18.     int c = getCount(l, lNext);
  19.     char *v = new char[c];
  20.     string tmp = w.substr(l - c, l);
  21.     MPI_Sendrecv(tmp.c_str(), tmp.length(), MPI_CHAR, next, 0, v, c, MPI_CHAR, prev, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  22.     w = string(v, c) + w.substr(0, l - c);
  23.     delete[] v;
  24.  
  25.     lPrev = w.length();
  26.     MPI_Sendrecv(&l, 1, MPI_INT, next, 0, &lPrev, 1, MPI_INT, prev, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  27.     c = getCount(l, lPrev);
  28.     v = new char[c];
  29.     tmp = w.substr(0, c);
  30.     MPI_Sendrecv(tmp.c_str(), tmp.length(), MPI_CHAR, prev, 0, v, c, MPI_INT, next, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
  31.    
  32.     string tmp2 = string(v, c);
  33.     delete[] v;
  34.     return w.substr(c, l) + tmp2;
  35. }