PSCF v1.1
MpiFileIo.h
1#ifndef UTIL_MPI_FILE_IO_H
2#define UTIL_MPI_FILE_IO_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/global.h>
12
13#include <iostream>
14#include <string>
15
16namespace Util
17{
18
34 {
35
36 public:
37
41 MpiFileIo();
42
46 MpiFileIo(const MpiFileIo& other);
47
51 bool isIoProcessor() const;
52
53 #ifdef UTIL_MPI
57 void setIoCommunicator(MPI::Intracomm& communicator);
58
62 void clearCommunicator();
63
67 bool hasIoCommunicator() const;
68
72 MPI::Intracomm& ioCommunicator() const;
73 #endif
74
75 private:
76
78 bool isIoProcessor_;
79
80 #ifdef UTIL_MPI
82 MPI::Intracomm* communicatorPtr_;
83 #endif
84
85 };
86
87 // Inline methods
88
89 /*
90 * Should this processor do file I/O ?
91 */
92 inline bool MpiFileIo::isIoProcessor() const
93 { return isIoProcessor_; }
94
95 #ifdef UTIL_MPI
96 /*
97 * Does this processor have a communicator?
98 */
99 inline bool MpiFileIo::hasIoCommunicator() const
100 { return (communicatorPtr_ != 0); }
101
102 /*
103 * Get the communicator.
104 */
105 inline MPI::Intracomm& MpiFileIo::ioCommunicator() const
106 {
107 assert(communicatorPtr_);
108 return *communicatorPtr_;
109 }
110 #endif
111}
112
113#endif
Identifies whether this processor may do file I/O.
Definition: MpiFileIo.h:34
MPI::Intracomm & ioCommunicator() const
Get the MPI communicator by reference.
Definition: MpiFileIo.h:105
MpiFileIo()
Constructor.
Definition: MpiFileIo.cpp:18
bool isIoProcessor() const
Can this processor do file I/O ?
Definition: MpiFileIo.h:92
void setIoCommunicator(MPI::Intracomm &communicator)
Set the communicator.
Definition: MpiFileIo.cpp:36
bool hasIoCommunicator() const
Does this object have an associated MPI communicator?
Definition: MpiFileIo.h:99
void clearCommunicator()
Clear (nullify) the communicator.
Definition: MpiFileIo.cpp:46
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1