Epetra Package Browser (Single Doxygen Collection)
Development
Toggle main menu visibility
Loading...
Searching...
No Matches
test
FECrsMatrix
FECrsMatrix/fematrix2.cpp
Go to the documentation of this file.
1
#ifdef HAVE_MPI
2
/*--------------------------------------------------------------------*/
3
#include <time.h>
4
#include "mpi.h"
5
#include "
Epetra_FECrsMatrix.h
"
6
#include "
Epetra_Map.h
"
7
#include "
Epetra_MpiComm.h
"
8
9
//This program was contributed by a user (Eric Marttila) to
10
//demonstrate a performance problem when filling an entire
11
//FECrsMatrix on a single processor and then letting
12
//GlobalAssemble distribute the data according to the Epetra_Map
13
//that the matrix was constructed with.
14
//
15
//Using profile data generated by running this program, we
16
//made changes to FECrsMatrix and improved the performance of
17
//inserting non-local data.
18
19
int
main
(
int
argCount,
char
**argValue)
20
{
21
int
ierr;
22
MPI_Init(&argCount,&argValue);
23
Epetra_MpiComm
Comm(MPI_COMM_WORLD);
24
const
int
rank = Comm.MyPID();
25
26
// Construct a Map
27
int
nGlobalElements = 10000;
//10,000 is deliberately small for nightly testing purposes.
28
// Set to 1 million for performance testing.
29
30
Epetra_Map
Map(nGlobalElements, 0, Comm);
31
32
// Create a matrix
33
Epetra_FECrsMatrix
A(
Copy
, Map, 1);
34
35
time_t startTime = 0;
36
if
(rank == 0) {
37
startTime = time(0);
38
}
39
40
// Fill matrix on the master process
41
if
(rank == 0) {
42
double
values[1];
43
int
indices[1];
44
const
int
numEntries = 1;
45
46
for
(
int
globalRowIdx=0; globalRowIdx<nGlobalElements; ++globalRowIdx) {
47
indices[0] = globalRowIdx;
48
values[0] = 3.2 + globalRowIdx*0.01;
49
50
if
(globalRowIdx % 5000 == 0) {
51
cerr <<
"About to insert row "
<< globalRowIdx <<
"\n"
;
52
}
53
54
ierr = A.InsertGlobalValues( globalRowIdx, numEntries,
55
(
const
double
*)&values[0],
56
(
const
int
*)&indices[0] );
57
58
assert(ierr==0);
59
}
60
}
61
62
double
insertionTime = 0;
63
if
(rank == 0) {
64
time_t endTime = time(0);
65
insertionTime = difftime(endTime, startTime);
66
}
67
68
// Finish up
69
ierr = A.GlobalAssemble();
70
assert(ierr==0);
71
72
if
(rank == 0) {
73
cerr <<
"insertion time = "
<< insertionTime <<
" (seconds)\n"
;
74
}
75
76
77
MPI_Finalize();
78
79
return
0;
80
}
81
/*--------------------------------------------------------------------*/
82
#else
83
int
main
(
int
,
char
**) {
84
return
0;
85
}
86
#endif
87
Copy
@ Copy
Definition
Epetra_DataAccess.h:55
Epetra_FECrsMatrix.h
Epetra_Map.h
Epetra_MpiComm.h
main
int main(int, char **)
Definition
FECrsMatrix/fematrix2.cpp:83
Epetra_FECrsMatrix
Epetra Finite-Element CrsMatrix.
Definition
Epetra_FECrsMatrix.h:120
Epetra_Map
Epetra_Map: A class for partitioning vectors and matrices.
Definition
Epetra_Map.h:119
Epetra_MpiComm
Epetra_MpiComm: The Epetra MPI Communication Class.
Definition
Epetra_MpiComm.h:64
Generated by
1.17.0