Epetra Package Browser (Single Doxygen Collection) Development
fevector.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 #include "Epetra_FEVector.h"
00003 
00004 #ifdef HAVE_MPI
00005 
00006 #include <time.h>
00007 #include "mpi.h"
00008 #include "Epetra_Map.h"
00009 #include "Epetra_MpiComm.h"
00010 
00011 int main(int argCount, char **argValue)
00012 {
00013   int ierr;
00014   MPI_Init(&argCount,&argValue);
00015   Epetra_MpiComm Comm(MPI_COMM_WORLD);
00016   const int rank = Comm.MyPID();
00017 
00018   // Construct a Map
00019   int nGlobalElements = 1000000;
00020   Epetra_Map Map(nGlobalElements, 0, Comm);
00021 
00022   // Create a vector
00023   Epetra_FEVector b(Map, 1);
00024 
00025   time_t startTime = 0;
00026   if (rank == 0) {
00027     startTime = time(0);
00028   }
00029 
00030   // Fill matrix on the master process
00031   if (rank == 0) {
00032     double values[1];
00033     int    indices[1];
00034 
00035     for (int globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
00036       indices[0] = globalRowIdx;
00037       values[0] = 3.2 + globalRowIdx*0.01;
00038 
00039       if (globalRowIdx % 10000 == 0) {
00040   std::cerr << "About to insert row " << globalRowIdx << "\n";
00041       }
00042 
00043       ierr = b.ReplaceGlobalValues(1, (const int *)&indices[0],
00044            (const double *)&values[0]);
00045       assert(ierr==0);
00046     }
00047   }
00048 
00049   double insertionTime = 0;
00050   if (rank == 0) {
00051     time_t endTime = time(0);
00052     insertionTime = difftime(endTime, startTime);
00053   }
00054 
00055   // Finish up
00056   ierr = b.GlobalAssemble();
00057   assert(ierr==0);
00058 
00059   if (rank == 0) {
00060     std::cerr << "insertion time = " << insertionTime << " (seconds)\n";
00061   }
00062 
00063 
00064   MPI_Finalize();
00065 
00066   return 0;
00067 }
00068 #else
00069 int main(int,char**)
00070 {
00071   return 0;
00072 }
00073 #endif
00074 /*--------------------------------------------------------------------*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines