Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fevector.cpp
Go to the documentation of this file.
1 /*--------------------------------------------------------------------*/
2 #include "Epetra_FEVector.h"
3 
4 #ifdef HAVE_MPI
5 
6 #include <time.h>
7 #include "mpi.h"
8 #include "Epetra_Map.h"
9 #include "Epetra_MpiComm.h"
10 
11 int main(int argCount, char **argValue)
12 {
13  int ierr;
14  MPI_Init(&argCount,&argValue);
15  Epetra_MpiComm Comm(MPI_COMM_WORLD);
16  const int rank = Comm.MyPID();
17 
18  // Construct a Map
19  int nGlobalElements = 1000000;
20  Epetra_Map Map(nGlobalElements, 0, Comm);
21 
22  // Create a vector
23  Epetra_FEVector b(Map, 1);
24 
25  time_t startTime = 0;
26  if (rank == 0) {
27  startTime = time(0);
28  }
29 
30  // Fill matrix on the master process
31  if (rank == 0) {
32  double values[1];
33  int indices[1];
34 
35  for (int globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
36  indices[0] = globalRowIdx;
37  values[0] = 3.2 + globalRowIdx*0.01;
38 
39  if (globalRowIdx % 10000 == 0) {
40  std::cerr << "About to insert row " << globalRowIdx << "\n";
41  }
42 
43  ierr = b.ReplaceGlobalValues(1, (const int *)&indices[0],
44  (const double *)&values[0]);
45  assert(ierr==0);
46  }
47  }
48 
49  double insertionTime = 0;
50  if (rank == 0) {
51  time_t endTime = time(0);
52  insertionTime = difftime(endTime, startTime);
53  }
54 
55  // Finish up
56  ierr = b.GlobalAssemble();
57  assert(ierr==0);
58 
59  if (rank == 0) {
60  std::cerr << "insertion time = " << insertionTime << " (seconds)\n";
61  }
62 
63 
64  MPI_Finalize();
65 
66  return 0;
67 }
68 #else
69 int main(int,char**)
70 {
71  return 0;
72 }
73 #endif
74 /*--------------------------------------------------------------------*/
Epetra_Map: A class for partitioning vectors and matrices.
Definition: Epetra_Map.h:119
Epetra_MpiComm: The Epetra MPI Communication Class.
Epetra Finite-Element Vector.
int main(int argc, char *argv[])