Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Core Modules
dune-common
Commits
ded47e44
Commit
ded47e44
authored
1 year ago
by
Simon Praetorius
Committed by
Santiago Ospina De Los Ríos
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Use Mayers' singleton pattern to initialize MPIHelper
parent
1c46e0dd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1332
Use Mayers' singleton pattern to initialize MPIHelper
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dune/common/parallel/mpihelper.hh
+38
-15
38 additions, 15 deletions
dune/common/parallel/mpihelper.hh
python/dune/common/_common.cc
+1
-3
1 addition, 3 deletions
python/dune/common/_common.cc
with
39 additions
and
18 deletions
dune/common/parallel/mpihelper.hh
+
38
−
15
View file @
ded47e44
...
...
@@ -240,26 +240,50 @@ namespace Dune
* ...
* }
* \endcode
*
* The MPIHelper will be globally initialized on its first call.
* Afterwards, all arguments to this function will be ignored.
*
* @param argc The number of arguments provided to main.
* @param argv The arguments provided to main.
*/
DUNE_EXPORT
static
MPIHelper
&
instance
(
int
&
argc
,
char
**&
argv
)
{
// create singleton instance
if
(
!
instance_
){
static
std
::
mutex
mutex
;
std
::
lock_guard
<
std
::
mutex
>
guard
(
mutex
);
if
(
!
instance_
)
instance_
.
reset
(
new
MPIHelper
(
argc
,
argv
));
}
return
*
instance_
;
return
instance
(
&
argc
,
&
argv
);
}
DUNE_EXPORT
static
MPIHelper
&
instance
()
/**
* @brief Get the singleton instance of the helper.
*
* This method can be called either without any arguments,
* or with the same arguments that the main method of the
* program was called, passed as pointer:
* \code
* int main(int argc, char** argv){
* MPIHelper::instance();
* // or: MPIHelper::instance(&argc, &argv);
* // program code comes here
* ...
* }
* \endcode
*
* The MPIHelper will be globally initialized on its first call.
* Afterwards, all arguments to this function will be ignored.
*
* @note This overload accepts all arguments by pointer similar
* to the `MPI_Init` function and allows to pass `nullptr` for
* all arguments.
*
* @relates instance(int&, char**&)
*
* @param argc The number of arguments provided to main.
* @param argv The arguments provided to main.
*/
DUNE_EXPORT
static
MPIHelper
&
instance
(
int
*
argc
=
nullptr
,
char
***
argv
=
nullptr
)
{
if
(
!
instance_
)
DUNE_THROW
(
InvalidStateException
,
"MPIHelper not initialized! Call MPIHelper::
instance
(
argc, argv
) with arguments first."
)
;
return
*
instance
_
;
assert
((
argc
==
nullptr
)
==
(
argv
==
nullptr
));
static
MPIHelper
instance
{
argc
,
argv
}
;
return
instance
;
}
/**
...
...
@@ -289,10 +313,9 @@ namespace Dune
int
size_
;
bool
initializedHere_
;
void
prevent_warning
(
int
){}
static
inline
std
::
unique_ptr
<
MPIHelper
>
instance_
=
{};
//! \brief calls MPI_Init with argc and argv as parameters
MPIHelper
(
int
&
argc
,
char
**
&
argv
)
MPIHelper
(
int
*
argc
,
char
**
*
argv
)
:
initializedHere_
(
false
)
{
int
wasInitialized
=
-
1
;
...
...
@@ -301,7 +324,7 @@ namespace Dune
{
rank_
=
-
1
;
size_
=
-
1
;
static
int
is_initialized
=
MPI_Init
(
&
argc
,
&
argv
);
static
int
is_initialized
=
MPI_Init
(
argc
,
argv
);
prevent_warning
(
is_initialized
);
initializedHere_
=
true
;
}
...
...
This diff is collapsed.
Click to expand it.
python/dune/common/_common.cc
+
1
−
3
View file @
ded47e44
...
...
@@ -26,8 +26,6 @@ PYBIND11_MODULE( _common, module )
Dune
::
Python
::
registerDynamicVector
<
double
>
(
module
);
Dune
::
Python
::
registerDynamicMatrix
<
double
>
(
module
);
int
argc
=
0
;
char
**
argv
=
NULL
;
Dune
::
MPIHelper
::
instance
(
argc
,
argv
);
Dune
::
MPIHelper
::
instance
();
Dune
::
Python
::
registerCommunication
(
module
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment