Epetra Package Browser (Single Doxygen Collection)
Development
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
example
Lessons
Lesson01-Init
lesson01_no_mpi.cpp
Go to the documentation of this file.
1
8
#include <Epetra_config.h>
9
// Wrapper for a "communicator" containing only one process. This
10
// header file always exists, whether or not Epetra was built with MPI
11
// enabled.
12
#include <
Epetra_SerialComm.h
>
13
#include <
Epetra_Version.h
>
14
15
#include <cstdlib>
16
#include <sstream>
17
#include <stdexcept>
18
19
//
20
// ... Your other include files go here ...
21
//
22
23
24
// Do something with the given communicator. In this case, we just
25
// print Epetra's version to the given output stream, on Process 0.
26
void
27
exampleRoutine
(
const
Epetra_Comm
& comm,
28
std::ostream& out)
29
{
30
if
(comm.
MyPID
() == 0) {
31
// On (MPI) Process 0, print out the Epetra software version.
32
out <<
Epetra_Version
() << std::endl << std::endl;
33
}
34
}
35
36
int
37
main
(
int
/* argc */
,
char
*
/* argv */
[])
38
{
39
// These "using" declarations make the code more concise, in that
40
// you don't have to write the namespace along with the class or
41
// object name. This is especially helpful with commonly used
42
// things like std::endl.
43
using
std::cout;
44
using
std::endl;
45
46
// Make a "serial" (non-MPI) communicator. It doesn't actually
47
// "communicate," because it only has one process, whose rank is
48
// always 0. Epetra_SerialComm is a subclass of Epetra_Comm, so you
49
// may use it wherever an Epetra_Comm is required.
50
Epetra_SerialComm
comm;
51
52
// Epetra_Comm has methods that wrap basic MPI functionality.
53
// MyPID() is equivalent to MPI_Comm_rank, and NumProc() to
54
// MPI_Comm_size.
55
//
56
// With a "serial" communicator, the rank is always 0, and the
57
// number of processes is always 1.
58
const
int
myRank = comm.
MyPID
();
59
const
int
numProcs = comm.
NumProc
();
60
61
// Test the two assertions in the previous comment.
62
if
(numProcs != 1) {
63
std::ostringstream err;
64
err <<
"This is a serial (non-MPI) example, but the number of processes "
65
<<
"in the Epetra_Comm is "
<< numProcs <<
" != 1. Please report "
66
<<
"this bug."
;
67
throw
std::logic_error (err.str ());
68
}
69
if
(myRank != 0) {
70
std::ostringstream err;
71
err <<
"This is a serial (non-MPI) example, but the rank of the calling "
72
"process in the Epetra_Comm is "
<< myRank <<
" != 0. Please report "
73
"this bug."
;
74
throw
std::logic_error (err.str ());
75
}
76
77
// Do something with the new communicator.
78
exampleRoutine
(comm, cout);
79
80
// This tells the Trilinos test framework that the test passed.
81
if
(myRank == 0) {
82
cout <<
"End Result: TEST PASSED"
<< endl;
83
}
84
85
return
0;
86
}
Epetra_SerialComm::MyPID
int MyPID() const
Return my process ID.
Definition:
Epetra_SerialComm.h:432
Epetra_Version
std::string Epetra_Version()
Definition:
Epetra_Version.h:47
Epetra_SerialComm.h
Epetra_Comm::MyPID
virtual int MyPID() const =0
Return my process ID.
Epetra_Comm
Epetra_Comm: The Epetra Communication Abstract Base Class.
Definition:
Epetra_Comm.h:73
Epetra_SerialComm::NumProc
int NumProc() const
Returns total number of processes (always returns 1 for SerialComm).
Definition:
Epetra_SerialComm.h:435
Epetra_SerialComm
Epetra_SerialComm: The Epetra Serial Communication Class.
Definition:
Epetra_SerialComm.h:61
main
int main(int argc, char *argv[])
Definition:
example/C_wrappers/c_main.c:49
Epetra_Version.h
exampleRoutine
void exampleRoutine(const Epetra_Comm &comm, std::ostream &out)
Definition:
lesson01_mpi_on_its_own.cpp:39
Generated by
1.8.5