Exemplo n.º 1
0
void MPIWrapper::allGatherCompact(const Epetra_Comm &Comm, FieldContainer<Scalar> &gatheredValues,
                                  FieldContainer<Scalar> &myValues, FieldContainer<int> &offsets)
{
  int mySize = myValues.size();
  int totalSize;
  Comm.SumAll(&mySize, &totalSize, 1);

  int myOffset = 0;
  Comm.ScanSum(&mySize,&myOffset,1);

  myOffset -= mySize;

  gatheredValues.resize(totalSize);
  for (int i=0; i<mySize; i++)
  {
    gatheredValues[myOffset+i] = myValues[i];
  }
  MPIWrapper::entryWiseSum(Comm, gatheredValues);

  offsets.resize(Comm.NumProc());
  offsets[Comm.MyPID()] = myOffset;
  MPIWrapper::entryWiseSum(Comm, offsets);
}
Exemplo n.º 2
0
static void printMatrix(const char *txt, int *myA, int *myX, int *myB,
                        int numRows, int numCols, const Epetra_Comm &comm)
{
  int me = comm.MyPID();

  int *A = new int [numRows * numCols];
  int *x = NULL;
  int *b = NULL;

  comm.SumAll(myA, A, numRows * numCols);

  if (myX){
    x = new int [numCols];
    comm.SumAll(myX, x, numCols);
  }
  if (myB){
    b = new int [numRows];
    comm.SumAll(myB, b, numRows);
  }

  if (me == 0){
    std::cout << txt << std::endl;

    std::cout << "  ";
    for (int j=0; j<numCols; j++){
      std::cout << j%10 ;
    }
    if (x)
      std::cout << "    LHS";
    if (b)
      std::cout << "        RHS";

    std::cout << std::endl;

    int *row = A;
 
    for (int i=0; i < numRows; i++, row += numCols){
      std::cout << i%10 << " ";
      for (int j=0; j < numCols; j++){
        if (row[j] > 0){
          std::cout << row[j]-1;
        }
        else{
          std::cout << " ";
        }
      }
      std::cout << " " << i%10 ;

      if (x && (i < numCols)){
        std::cout << "   " << x[i]-1;
      }
      if ((i == 0) && b){
        std::cout << "    =  [";
        for (int j=0; j<numRows; j++){
          std::cout << b[j]-1;
        }
        std::cout << "]";
      }
      std::cout << std::endl;
    
    }
    std::cout << "  ";
    for (int j=0; j<numCols; j++){
      std::cout << j%10 ;
    }

    int columnsRemaining = numCols - numRows;
    int next_x = numRows;

    if ((columnsRemaining > 0) && x){
      std::cout << "     " << x[next_x++] - 1 << std::endl;
      columnsRemaining--;
      int pad = numCols + 7;
      while(columnsRemaining){ 
        for( int i=0; i < pad; i++){
          std::cout << " ";
        }
        std::cout << x[next_x++] - 1 << std::endl;
        columnsRemaining--;
      }
    }
    std::cout << std::endl;
  }

  delete [] A;
  if (x) delete [] x;
  if (b) delete [] b;
}