Epetra Package Browser (Single Doxygen Collection) Development
LL/fematrix2.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_MPI
00002 /*--------------------------------------------------------------------*/
00003 #include <time.h>
00004 #include "mpi.h"
00005 #include "Epetra_FECrsMatrix.h"
00006 #include "Epetra_Map.h"
00007 #include "Epetra_MpiComm.h"
00008 
00009 //This program was contributed by a user (Eric Marttila) to
00010 //demonstrate a performance problem when filling an entire
00011 //FECrsMatrix on a single processor and then letting
00012 //GlobalAssemble distribute the data according to the Epetra_Map
00013 //that the matrix was constructed with.
00014 //
00015 //Using profile data generated by running this program, we
00016 //made changes to FECrsMatrix and improved the performance of
00017 //inserting non-local data.
00018 
00019 int main(int argCount, char **argValue)
00020 {
00021   int ierr;
00022   MPI_Init(&argCount,&argValue);
00023   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00024   const int rank = Comm.MyPID();
00025 
00026   // Construct a Map 
00027   int nGlobalElements = 10000;//10,000 is deliberately small for nightly testing purposes.
00028                              // Set to 1 million for performance testing.
00029 
00030   Epetra_Map Map(nGlobalElements, 0, Comm);
00031 
00032   // Create a matrix
00033   Epetra_FECrsMatrix A(Copy, Map, 1);
00034 
00035   time_t startTime = 0;
00036   if (rank == 0) {
00037     startTime = time(0);
00038   }
00039 
00040   // Fill matrix on the master process
00041   if (rank == 0) {
00042     double values[1];
00043     int    indices[1];
00044     const int numEntries = 1;
00045 
00046     for (int globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
00047       indices[0] = globalRowIdx;
00048       values[0] = 3.2 + globalRowIdx*0.01;
00049 
00050       if (globalRowIdx % 5000 == 0) {
00051   cerr << "About to insert row " << globalRowIdx << "\n";
00052       }
00053 
00054       ierr = A.InsertGlobalValues( globalRowIdx, numEntries,
00055            (const double *)&values[0],
00056            (const int *)&indices[0] );
00057 
00058       assert(ierr==0);
00059     }
00060   }
00061 
00062   double insertionTime = 0;
00063   if (rank == 0) {
00064     time_t endTime = time(0);
00065     insertionTime = difftime(endTime, startTime);
00066   }
00067 
00068   // Finish up
00069   ierr = A.GlobalAssemble();
00070   assert(ierr==0);
00071 
00072   if (rank == 0) {
00073     cerr << "insertion time = " << insertionTime << " (seconds)\n";
00074   }
00075 
00076 
00077   MPI_Finalize();
00078 
00079   return 0;
00080 }
00081 /*--------------------------------------------------------------------*/
00082 #else
00083 int main(int,char**) {
00084   return 0;
00085 }
00086 #endif
00087 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines