45 #include "../epetra_test_err.h" 
   62                      bool verbose, 
bool verbose1,
 
   63                      int& NumProc, 
int& rank);
 
   70 int main(
int argc, 
char* argv[]) {
 
   72   bool verbose1 = 
false; 
 
   74   if (argc>1) 
if (argv[1][0]==
'-' && argv[1][1]==
'v') verbose1 = 
true;
 
   85   if(verbose1) cout << 
"Testing Epetra_SerialComm..." << endl;
 
   87   if (verbose1) cout << serialcomm << endl;
 
   90   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
   92   int numProc = serialcomm.
NumProc();
 
   95   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
   97   if(verbose1) cout << 
"SerialComm Clone.." << endl;
 
   99   ierr = 
checkCommMethods(*cloned_serialcomm, verbose, verbose1, numProc, rank);
 
  100   delete cloned_serialcomm;
 
  102   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  106   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  116   if(verbose1) cout << 
"Testing Epetra_MpiComm..." << endl;
 
  117   MPI_Init(&argc,&argv);
 
  118   MPI_Comm_size(MPI_COMM_WORLD, &size);
 
  119   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
 
  123   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  124   MPI_Comm MPIComm1 = petracomm.
Comm();
 
  126   MPI_Comm_size(MPIComm1, &size1);
 
  127   MPI_Comm_rank(MPIComm1, &rank1);
 
  128   if (verbose1) cout << petracomm <<  
".  Using MPI_Comm from Petra_Comm:" 
  129                            << 
" Processor " << rank1 << 
" of " << size1
 
  130                            << 
" (should be the same)." << endl;
 
  139   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  142   if(verbose1) cout << 
"MpiComm Clone.." << endl;
 
  145   delete cloned_mpicomm;
 
  147   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  153   if (verbose1 && ierr==0) cout << 
"Checked OK\n\n" <<endl;
 
  170   int MyPID = petracomm.
MyPID();
 
  177   for (
int j=0; j<rank+1; j++)
 
  178     for (
int i=0; i<1000000; i++)
 
  179       sum += ((
double )rand())/((double) RAND_MAX);
 
  181   if (verbose) cout << 
"Processor " << MyPID
 
  182                     << 
" Time to reach barrier: " 
  185   if (verbose) cout << 
"Processor " << MyPID << 
" Sum result  " 
  186                     << sum << 
" Time to get beyond barrier: " 
  196   int MyPID = petracomm.
MyPID();
 
  198   int NumProc = petracomm.
NumProc();
 
  211   verbose = (petracomm.
MyPID() == 0);  
 
  216   int* iInputs = 
new int[count]; 
 
  217   for (i=0; i<count; i++)
 
  218     iInputs[i] = 10*(i + rank - 2) + rank;
 
  223   double* dInputs = 
new double[count]; 
 
  224   for (i=0; i<count; i++)
 
  225     dInputs[i] = pow(2.0,i-rank);
 
  232   int* iVals = 
new int[count];
 
  234     for (i=0; i<count; i++)
 
  238   int* iBVals = 
new int[count]; 
 
  239   for (i=0; i<count; i++)
 
  241   double* dVals = 
new double[count];
 
  243      for (i=0; i<count; i++)
 
  244        dVals[i] = 
double(i); 
 
  246   double* dBVals = 
new double[count]; 
 
  247   for (i=0; i<count; i++)
 
  250   long long* llVals = 
new long long[count];
 
  252      for (i=0; i<count; i++)
 
  253        llVals[i] = (
long long)i+INT_MAX; 
 
  255   long long* llBVals = 
new long long[count]; 
 
  256   for (i=0; i<count; i++)
 
  257     llBVals[i] = (
long long)i+INT_MAX; 
 
  259   const char *cConst = 
"Heidi, do you want a cookie?";
 
  260   int cCount = strlen(cConst)+1;
 
  261   char* cVals = 
new char[cCount];
 
  263      strcpy(cVals, cConst);        
 
  264      cVals[cCount-1] = 
'\0';       
 
  266   char* cBVals = 
new char[cCount]; 
 
  268   strcpy(cBVals, cConst);          
 
  269   cBVals[cCount-1] = 
'\0';         
 
  272   int* iMyGlobalMaxs = 
new int[count];
 
  273   for (i=0; i<count; i++)
 
  274     iMyGlobalMaxs[i]=10 * (i + NumProc-1 -2) +  NumProc-1; 
 
  276   double* dMyGlobalMaxs = 
new double[count];
 
  277   for (i=0; i<count; i++)
 
  278     dMyGlobalMaxs[i]= pow(2.0,i); 
 
  283   int* iMyGlobalMins = 
new int[count];
 
  284   for (i=0; i<count; i++)
 
  285     iMyGlobalMins[i]= 10 * (i - 2); 
 
  287   double* dMyGlobalMins = 
new double[count];
 
  288   for (i=0; i<count; i++)
 
  289     dMyGlobalMins[i]= pow(2.0,i-(NumProc-1)); 
 
  294   int* iMyGlobalSums = 
new int[count];
 
  295   for (i=0; i<count; i++){
 
  297     for (j=0; j<NumProc; j++)
 
  298       iMyGlobalSums[i] += 10*(i+j-2) + j;
 
  301   double* dMyGlobalSums = 
new double[count];
 
  302   for (i=0; i<count; i++){
 
  304     for (j=0; j<NumProc; j++)
 
  305       dMyGlobalSums[i] += pow(2.0,i-j);
 
  310   int* iMyScanSums = 
new int[count];
 
  311   for (i=0; i<count; i++)
 
  312     iMyScanSums[i] = 
int((rank+1)*(10*(2*i+rank-4)+rank)*.5);
 
  315   double* dMyScanSums = 
new double[count];
 
  316   for (i=0; i<count; i++) {
 
  318     for (j=0; j<=rank; j++)
 
  319       dMyScanSums[i] += pow(2.0,i-j); 
 
  324   int totalVals = count*NumProc;
 
  325   int* iMyOrderedVals = 
new int[totalVals];
 
  326   double* dMyOrderedVals = 
new double[totalVals];
 
  328   for (j=0; j<NumProc; j++) {
 
  329     for (i=0; i<count; i++) {
 
  330       iMyOrderedVals[k] = 10*(i + j - 2) + j;; 
 
  332       dMyOrderedVals[k] = pow(2.0,i-j); 
 
  345       cout << 
"The values on the root processor are: ";
 
  347       cout << 
"The values on processor " << rank << 
" are: ";
 
  348     for (i=0; i<count; i++)
 
  349       cout << iVals[i] << 
" ";
 
  354   for (i=0; i<count; i++)
 
  355     forierr += !(iVals[i] == iBVals[i]); 
 
  360   if (verbose) cout << endl << 
"Broadcast (type int) test passed!" << endl << endl;
 
  367       cout << 
"The values on the root processor are: ";
 
  369       cout << 
"The values on processor " << rank << 
" are: ";
 
  370     for (i=0; i<count; i++)
 
  371       cout << dVals[i] << 
" ";
 
  375   for (i=0; i<count; i++)
 
  376     forierr += !(dVals[i] == dBVals[i]); 
 
  381   if (verbose) cout << endl << 
"Broadcast (type double) test passed!" << endl << endl;
 
  388       cout << 
"The values on the root processor are: ";
 
  390       cout << 
"The values on processor " << rank << 
" are: ";
 
  391     for (i=0; i<count; i++)
 
  392       cout << llVals[i] << 
" ";
 
  396   for (i=0; i<count; i++)
 
  397     forierr += !(llVals[i] == llBVals[i]); 
 
  402   if (verbose) cout << endl << 
"Broadcast (type long long) test passed!" << endl << endl;
 
  409       cout << 
"The values on the root processor are: " << cVals << endl;
 
  411       cout << 
"The values on processor " << rank << 
" are: " << cVals << endl;
 
  414   for (i=0; i<cCount; i++)
 
  415     forierr += !(cVals[i] == cBVals[i]); 
 
  422     cout << endl << 
"Broadcast (type char) test passed!" << endl << endl;
 
  427   int* iGlobalMaxs = 
new int[count];
 
  429     cout << 
"The values on processor " << rank << 
" are: ";
 
  430     for (i=0; i<count; i++)
 
  431       cout << iInputs[i] << 
" ";
 
  438     cout << 
"The max values according to processor " << rank << 
" are: ";
 
  439     for (i=0; i<count; i++)
 
  440       cout << iGlobalMaxs[i] << 
" ";
 
  444   for (i=0; i<count; i++)
 
  445     forierr += !(iMyGlobalMaxs[i] == iGlobalMaxs[i]);
 
  448   delete [] iGlobalMaxs;
 
  449   delete [] iMyGlobalMaxs;
 
  451   if (verbose) cout << endl << 
"MaxAll (type int) test passed!" << endl << endl;
 
  455   double* dGlobalMaxs = 
new double[count];
 
  457     cout << 
"The values on processor " << rank << 
" are: ";
 
  458     for (i=0; i<count; i++)
 
  459       cout << dInputs[i] << 
" ";
 
  466     cout << 
"The max values according to processor " << rank << 
" are: ";
 
  467     for (i=0; i<count; i++)
 
  468       cout << dGlobalMaxs[i] << 
" ";
 
  472   for (i=0; i<count; i++)
 
  475   delete [] dGlobalMaxs;
 
  476   delete [] dMyGlobalMaxs;
 
  478   if (verbose) cout << endl << 
"MaxAll (type double) test passed!" << endl << endl;
 
  484   int* iGlobalMins = 
new int[count];
 
  486     cout << 
"The values on processor " << rank << 
" are: ";
 
  487     for (i=0; i<count; i++)
 
  488       cout << iInputs[i] << 
" ";
 
  495     cout << 
"The min values according to processor " << rank << 
" are: ";
 
  496     for (i=0; i<count; i++)
 
  497       cout << iGlobalMins[i] << 
" ";
 
  501   for (i=0; i<count; i++)
 
  502     forierr += !(iMyGlobalMins[i] == iGlobalMins[i]); 
 
  504   delete [] iGlobalMins;
 
  505   delete [] iMyGlobalMins;
 
  507   if (verbose) cout << endl << 
"MinAll (type int) test passed!" << endl << endl;
 
  511   double* dGlobalMins = 
new double[count];
 
  513     cout << 
"The values on processor " << rank << 
" are: ";
 
  514     for (i=0; i<count; i++)
 
  515       cout << dInputs[i] << 
" ";
 
  522     cout << 
"The min values according to processor " << rank << 
" are: ";
 
  523     for (i=0; i<count; i++)
 
  524       cout << dGlobalMins[i] << 
" ";
 
  528   for (i=0; i<count; i++)
 
  531   delete [] dGlobalMins;
 
  532   delete [] dMyGlobalMins;
 
  534   if (verbose) cout << endl << 
"MinAll (type double) test passed!" << endl << endl;
 
  540   int* iGlobalSums = 
new int[count];
 
  542     cout << 
"The values on processor " << rank << 
" are: ";
 
  543     for (i=0; i<count; i++)
 
  544       cout << iInputs[i] << 
" ";
 
  551     cout << 
"The sums of all values according to processor " << rank << 
" are: ";
 
  552     for (i=0; i<count; i++)
 
  553       cout << iGlobalSums[i] << 
" ";
 
  557   for (i=0; i<count; i++)
 
  558     forierr += !(iMyGlobalSums[i] == iGlobalSums[i]); 
 
  560   delete [] iGlobalSums;
 
  561   delete [] iMyGlobalSums;
 
  563   if (verbose) cout << endl << 
"SumAll (type int) test passed!" << endl << endl;
 
  567   double* dGlobalSums = 
new double[count];
 
  569     cout << 
"The values on processor " << rank << 
" are: ";
 
  570     for (i=0; i<count; i++)
 
  571       cout << dInputs[i] << 
" ";
 
  578     cout << 
"The sums of all values according to processor " << rank << 
" are: ";
 
  579     for (i=0; i<count; i++)
 
  580       cout << dGlobalSums[i] << 
" ";
 
  584   for (i=0; i<count; i++)
 
  588   delete [] dGlobalSums;
 
  589   delete [] dMyGlobalSums;
 
  591   if (verbose) cout << endl << 
"SumAll (type double) test passed!" << endl << endl;
 
  597   int* iScanSums = 
new int[count];
 
  599     cout << 
"The values on processor " << rank << 
" are: ";
 
  600     for (i=0; i<count; i++)
 
  601       cout << iInputs[i] << 
" ";
 
  609     cout << 
"The sums of all values on processors 0 - " << rank << 
" are: ";
 
  610     for (i=0; i<count; i++) {
 
  611       cout << iScanSums[i] << 
" ";
 
  616   for (i=0; i<count; i++)
 
  617     forierr += !(iMyScanSums[i] == iScanSums[i]);
 
  620   delete [] iMyScanSums;
 
  622   if (verbose) cout << endl << 
"ScanSum (type int) test passed!" << endl << endl;
 
  626   double* dScanSums = 
new double[count];
 
  628     cout << 
"The values on processor " << rank << 
" are: ";
 
  629     for (i=0; i<count; i++)
 
  630       cout << dInputs[i] << 
" ";
 
  638     cout << 
"The sums of all values on processors 0 - " << rank << 
" are: ";
 
  639     for (i=0; i<count; i++) {
 
  640       cout << dScanSums[i] << 
" ";
 
  645   for (i=0; i<count; i++)
 
  649   delete [] dMyScanSums;
 
  651   if (verbose) cout << endl << 
"ScanSum (type double) test passed!" << endl << endl;
 
  657   int* iOrderedVals = 
new int[totalVals];
 
  659     cout << 
"The values on processor " << rank << 
" are: ";
 
  660     for (i=0; i<count; i++)
 
  661       cout << iInputs[i] << 
" ";
 
  669     cout << 
"The combined list of all values from all processors according to processor " << rank << 
" is: ";
 
  670     for (i=0; i<totalVals; i++) {
 
  671       cout << iOrderedVals[i] << 
" ";
 
  676   for (i=0; i<totalVals; i++)
 
  677     forierr += !(iMyOrderedVals[i] == iOrderedVals[i]);
 
  679   delete [] iOrderedVals;
 
  680   delete [] iMyOrderedVals;
 
  682   if (verbose) cout << endl << 
"GatherAll (type int) test passed!" << endl << endl;
 
  686   double* dOrderedVals = 
new double[totalVals];
 
  688     cout << 
"The values on processor " << rank << 
" are: ";
 
  689     for (i=0; i<count; i++)
 
  690       cout << dInputs[i] << 
" ";
 
  698     cout << 
"The combined list of all values from all processors according to processor " << rank << 
" is: ";
 
  699     for (i=0; i<totalVals; i++) {
 
  700       cout << dOrderedVals[i] << 
" ";
 
  705   for (i=0; i<totalVals; i++)
 
  708   delete [] dOrderedVals;
 
  709   delete [] dMyOrderedVals;
 
  711   if (verbose) cout << endl << 
"GatherAll (type double) test passed!" << endl << endl;
 
  724   if(verbose) cout << 
"Testing Reference Counting... ";               
 
  729   if(verbose) cout << 
"Default constructor. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  734   int c1countold = c1count;
 
  738   if(verbose) cout << 
"Copy constructor(heap). \nc1= " << c1count << 
"  " << c1addr
 
  739                     << 
"\nc2= " << c2count << 
"  " << c2addr << endl;
 
  741   c1countold = c1count;
 
  745   if(verbose) cout << 
"c2 Deleted. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  751     c1countold = c1count;
 
  755     if(verbose) cout << 
"Copy constructor(stack). \nc1= " << c1count << 
"  " << c1addr
 
  756                       << 
"\nc2a= " << c2count << 
"  " << c2addr << endl;
 
  758   c1countold = c1count;
 
  762   if(verbose) cout << 
"c2a Destroyed. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  763   if(verbose) cout << 
"Assignment operator, post construction" << endl;
 
  769   if(verbose)cout << 
"Prior to assignment: \nc1=" << c1count << 
"  " << c1addr
 
  770                    << 
"\nc3=" << c3count << 
"  " << c3addr << endl;
 
  774   c1countold = c1count;
 
  778   if(verbose)cout << 
"After assignment: \nc1=" << c1count << 
"  " << c1addr
 
  779                    << 
"\nc3=" << c3count << 
"  " << c3addr << endl;
 
  787   if(verbose) cout << 
"Testing Reference Counting... ";               
 
  792   if(verbose) cout << 
"Default constructor. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  797   int c1countold = c1count;
 
  801   if(verbose) cout << 
"Copy constructor(heap). \nc1= " << c1count << 
"  " << c1addr
 
  802                     << 
"\nc2= " << c2count << 
"  " << c2addr << endl;
 
  804   c1countold = c1count;
 
  808   if(verbose) cout << 
"c2 Deleted. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  814     c1countold = c1count;
 
  818     if(verbose) cout << 
"Copy constructor(stack). \nc1= " << c1count << 
"  " << c1addr
 
  819                       << 
"\nc2a= " << c2count << 
"  " << c2addr << endl;
 
  821   c1countold = c1count;
 
  825   if(verbose) cout << 
"c2a Destroyed. \nc1= " << c1count << 
"  " << c1addr << endl;
 
  826   if(verbose) cout << 
"Assignment operator, post construction" << endl;
 
  832   if(verbose)cout << 
"Prior to assignment: \nc1=" << c1count << 
"  " << c1addr
 
  833                    << 
"\nc3=" << c3count << 
"  " << c3addr << endl;
 
  837   c1countold = c1count;
 
  841   if(verbose)cout << 
"After assignment: \nc1=" << c1count << 
"  " << c1addr
 
  842                    << 
"\nc3=" << c3count << 
"  " << c3addr << endl;
 
  852   int numExportIDs = numprocs;
 
  853   int* exportPIDs = 
new int[numExportIDs];
 
  854   for(
int p=0; p<numExportIDs; ++p) {
 
  858   bool deterministic = 
true;
 
  859   int numRemoteIDs = 0;
 
  862                                    deterministic, numRemoteIDs);
 
  866   int returnValue = numRemoteIDs == numExportIDs ? 0 : -99;
 
  868   delete [] exportPIDs;
 
  870   if (returnValue + err != 0) {
 
  871     return(returnValue + err);
 
  874   int* exportIDs = 
new int[numExportIDs];
 
  875   for(
int i=0; i<numExportIDs; ++i) {
 
  880   char* imports = NULL;
 
  882   err = distr->
Do((
char*)exportIDs, 
sizeof(
int),
 
  883                   len_imports, imports);
 
  887   if (len_imports > 0) {
 
const Epetra_MpiCommData * DataPtr() const 
Returns a pointer to the MpiCommData instance this MpiComm uses. 
 
Epetra_Distributor: The Epetra Gather/Scatter Setup Base Class. 
 
virtual int GatherAll(double *MyVals, double *AllVals, int Count) const =0
Epetra_Comm All Gather function. 
 
#define EPETRA_TEST_ERR(a, b)
 
Epetra_Comm * Clone() const 
Clone method. 
 
double ElapsedTime(void) const 
Epetra_Time elapsed time function. 
 
virtual int CreateFromSends(const int &NumExportIDs, const int *ExportPIDs, bool Deterministic, int &NumRemoteIDs)=0
Create Distributor object using list of process IDs to which we export. 
 
int NumProc() const 
Returns total number of processes. 
 
void Barrier() const 
Epetra_MpiComm Barrier function. 
 
int ReferenceCount() const 
Returns the reference count of MpiCommData. 
 
virtual int MinAll(double *PartialMins, double *GlobalMins, int Count) const =0
Epetra_Comm Global Min function. 
 
Epetra_MpiComm: The Epetra MPI Communication Class. 
 
std::string Epetra_Version()
 
virtual void Barrier() const =0
Epetra_Comm Barrier function. 
 
Epetra_Comm * Clone() const 
Clone method. 
 
virtual int MyPID() const =0
Return my process ID. 
 
const Epetra_SerialCommData * DataPtr() const 
Returns a pointer to the SerialCommData instance this SerialComm uses. 
 
Epetra_Time: The Epetra Timing Class. 
 
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const =0
Epetra_Comm Global Max function. 
 
virtual int SumAll(double *PartialSums, double *GlobalSums, int Count) const =0
Epetra_Comm Global Sum function. 
 
Epetra_Distributor * CreateDistributor() const 
Create a distributor object. 
 
void checkBarrier(Epetra_Comm &petracomm, bool verbose, int rank)
 
Epetra_SerialCommData: The Epetra Serial Communication Data Class. 
 
Epetra_Comm: The Epetra Communication Abstract Base Class. 
 
MPI_Comm Comm() const 
Extract MPI Communicator from a Epetra_MpiComm object. 
 
int NumProc() const 
Returns total number of processes (always returns 1 for SerialComm). 
 
virtual int Broadcast(double *MyVals, int Count, int Root) const =0
Epetra_Comm Broadcast function. 
 
virtual int Do(char *export_objs, int obj_size, int &len_import_objs, char *&import_objs)=0
Execute plan on buffer of export objects in a single step. 
 
Epetra_SerialComm: The Epetra Serial Communication Class. 
 
Epetra_MpiCommData: The Epetra Mpi Communication Data Class. 
 
virtual int NumProc() const =0
Returns total number of processes. 
 
int checkMpiDataClass(bool verbose)
 
int ReferenceCount() const 
Returns the reference count of SerialCommData. 
 
int checkRankAndSize(Epetra_Comm &petracomm, bool verbose, int rank, int size)
 
static double Chop(const double &Value)
Epetra_Util Chop method. Return zero if input Value is less than ChopValue. 
 
int main(int argc, char *argv[])
 
int checkDistributor(Epetra_Distributor *distr, Epetra_Comm &Comm)
 
Epetra_Distributor * CreateDistributor() const 
Create a distributor object. 
 
virtual int ScanSum(double *MyVals, double *ScanSums, int Count) const =0
Epetra_Comm Scan Sum function. 
 
int checkCommMethods(Epetra_Comm &petracomm, bool verbose, bool verbose1, int &NumProc, int &rank)
 
int checkSerialDataClass(bool verbose)