Ejemplo n.º 1
0
std::ostream& MLAPI::DistributedMatrix::
Print(std::ostream& os, const bool verbose) const
{
  if (GetMyPID() == 0) {

    os << std::endl;
    os << "*** MLAPI::DistributedMatrix ***" << std::endl;
    os << "Label = " << GetLabel() << std::endl;
    os << "Number of rows    = " << GetRangeSpace().GetNumGlobalElements() << std::endl;
    os << "Number of columns = " << GetDomainSpace().GetNumGlobalElements() << std::endl;
    os << std::endl;
    os.width(10); os << "row ID";
    os.width(10); os << "col ID";
    os.width(30); os << "value";
    os << std::endl;
    os << std::endl;
  }

  for (int iproc = 0 ; iproc < GetNumProcs() ; ++iproc) {

    if (GetMyPID() == iproc) {

      if (IsFillCompleted()) {
        for (int i = 0 ; i < NumMyRows() ; ++i) {
          int GRID = RangeMap_->GID(i);
          double* Values;
          int* Indices;
          int NumEntries;
          Matrix_->ExtractMyRowView(i, NumEntries, Values, Indices);
          for (int j = 0 ; j < NumEntries ; ++j) {
            os.width(10); os << GRID;
            os.width(10); os << Matrix_->RowMatrixColMap().GID(Indices[j]);
            os.width(30); os << Values[j];
            os << std::endl;
          }
        }
      }
      else {
        for (int i = 0 ; i < NumMyRows() ; ++i) {
          int GRID = RangeMap_->GID(i);
          double* Values;
          int* Indices;
          int NumEntries;
          Matrix_->ExtractGlobalRowView(GRID, NumEntries, Values, Indices);
          for (int j = 0 ; j < NumEntries ; ++j) {
            os.width(10); os << GRID;
            os.width(10); os << Indices[j];
            os.width(30); os << Values[j];
            os << std::endl;
          }
        }
      }
    }
    Barrier();
  }

  if (GetMyPID() == 0)
    os << std::endl;

  Barrier();

  return(os);
}
Ejemplo n.º 2
0
// ====================================================================== 
void Init() 
{
  if (ML_Comm_ == 0) ML_Comm_Create(&ML_Comm_);
  if (Epetra_Comm_ == 0) {
#ifdef HAVE_MPI
    Epetra_Comm_ = new Epetra_MpiComm(MPI_COMM_WORLD);
#else
    Epetra_Comm_ = new Epetra_SerialComm;
#endif
  }

  char * str = (char *) getenv("ML_BREAK_FOR_DEBUGGER");
  int i = 0, j = 0;
  char buf[80];
  char go = ' ';
  char hostname[80];
  if (str != NULL) i++;

  FILE * ML_capture_flag;
  ML_capture_flag = fopen("ML_debug_now","r");
  if(ML_capture_flag) {
    i++;
    fclose(ML_capture_flag);
  }

  GetEpetra_Comm().SumAll(&i, &j, 1);

  if (j != 0)
  {
    if (GetMyPID()  == 0) std::cout << "Host and Process Ids for tasks" << std::endl;
    for (i = 0; i < GetNumProcs() ; i++) {
      if (i == GetMyPID() ) {
#if defined(TFLOP) || defined(JANUS_STLPORT) || defined(COUGAR)
        sprintf(buf, "Host: %s   PID: %d", "janus", getpid());
#else
        gethostname(hostname, sizeof(hostname));
        sprintf(buf, "Host: %s\tMyPID(): %d\tPID: %d",
                hostname, GetMyPID(), getpid());
#endif
        printf("%s\n",buf);
        fflush(stdout);
#ifdef ICL
        Sleep(1);
#else
        sleep(1);
#endif
      }
    }
    if (GetMyPID() == 0) {
      printf("\n");
      printf("** Pausing because environment variable ML_BREAK_FOR_DEBUGGER has been set,\n");
      puts("** or file ML_debug_now has been created");
      printf("**\n");
      printf("** You may now attach debugger to the processes listed above.\n");
      printf( "**\n");
      printf( "** Enter a character to continue > "); fflush(stdout);
      scanf("%c",&go);
    }
  }

  ML_Set_PrintLevel(10);
}