Epetra Package Browser (Single Doxygen Collection) Development
Loading...
Searching...
No Matches
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
11int main(int argCount, char **argValue)
12{
13#ifndef NDEBUG
14 int ierr;
15#endif
16 MPI_Init(&argCount,&argValue);
17 Epetra_MpiComm Comm(MPI_COMM_WORLD);
18 const int rank = Comm.MyPID();
19
20 // Construct a Map
21 int nGlobalElements = 1000000;
22 Epetra_Map Map(nGlobalElements, 0, Comm);
23
24 // Create a vector
25 Epetra_FEVector b(Map, 1);
26
27 time_t startTime = 0;
28 if (rank == 0) {
29 startTime = time(0);
30 }
31
32 // Fill matrix on the master process
33 if (rank == 0) {
34 double values[1];
35 int indices[1];
36
37 for (int globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
38 indices[0] = globalRowIdx;
39 values[0] = 3.2 + globalRowIdx*0.01;
40
41 if (globalRowIdx % 10000 == 0) {
42 std::cerr << "About to insert row " << globalRowIdx << "\n";
43 }
44
45#ifndef NDEBUG
46 ierr =
47#endif
48 b.ReplaceGlobalValues(1, (const int *)&indices[0],
49 (const double *)&values[0]);
50 assert(ierr==0);
51 }
52 }
53
54 double insertionTime = 0;
55 if (rank == 0) {
56 time_t endTime = time(0);
57 insertionTime = difftime(endTime, startTime);
58 }
59
60 // Finish up
61#ifndef NDEBUG
62 ierr =
63#endif
64 b.GlobalAssemble();
65 assert(ierr==0);
66
67 if (rank == 0) {
68 std::cerr << "insertion time = " << insertionTime << " (seconds)\n";
69 }
70
71
72 MPI_Finalize();
73
74 return 0;
75}
76#else
77int main(int,char**)
78{
79 return 0;
80}
81#endif
82/*--------------------------------------------------------------------*/
Epetra Finite-Element Vector.
Epetra_Map: A class for partitioning vectors and matrices.
Definition: Epetra_Map.h:119
Epetra_MpiComm: The Epetra MPI Communication Class.
int main(int, char **)
Definition: fevector.cpp:77