Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
amdis-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
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
amdis
amdis-core
Commits
a79d1a4a
Commit
a79d1a4a
authored
5 years ago
by
Praetorius, Simon
Browse files
Options
Downloads
Patches
Plain Diff
output of single and all ranks and info function added
parent
62155381
Branches
Branches containing commit
No related tags found
1 merge request
!71
write only rank 0 in parallel
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/amdis/Output.hpp
+77
-31
77 additions, 31 deletions
src/amdis/Output.hpp
with
77 additions
and
31 deletions
src/amdis/Output.hpp
+
77
−
31
View file @
a79d1a4a
...
...
@@ -38,6 +38,11 @@
#endif
#endif
/// Level bound for output of additional information. See \ref info() and \ref info_()
#ifndef AMDIS_INFO_LEVEL
#define AMDIS_INFO_LEVEL 1
#endif
#define AMDIS_UNUSED(var) __attribute__((unused)) var
#define AMDIS_FUNCNAME(nn) AMDIS_UNUSED(const char *funcName); funcName = nn;
...
...
@@ -56,22 +61,27 @@ namespace AMDiS
namespace
Impl
{
template
<
class
OStream
,
class
...
Args
>
OStream
&
msg
(
OStream
&
out
,
bool
lineBreak
,
Args
&&
...
args
)
OStream
&
msg
_all
(
OStream
&
out
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
#if HAVE_MPI
if
(
Environment
::
mpiSize
()
>
1
&&
Environment
::
mpiRank
()
==
0
)
{
out
<<
"[0] "
;
fmt
::
print
(
out
,
FWD
(
args
)...);
if
(
lineBreak
)
{
out
<<
std
::
endl
;
}
}
else
if
(
Environment
::
mpiSize
()
==
1
)
{
fmt
::
print
(
out
,
FWD
(
args
)...);
if
(
lineBreak
)
{
out
<<
std
::
endl
;
}
}
if
(
Environment
::
mpiSize
()
>
1
)
fmt
::
print
(
out
,
"["
+
std
::
to_string
(
Environment
::
mpiRank
())
+
"] "
+
str
,
FWD
(
args
)...);
else
fmt
::
print
(
out
,
str
,
FWD
(
args
)...);
return
out
;
}
template
<
class
OStream
,
class
...
Args
>
OStream
&
msg
(
OStream
&
out
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
#ifdef AMDIS_MSG_ALL_RANKS
return
msg_all
(
out
,
str
,
FWD
(
args
)...);
#else
fmt
::
print
(
out
,
FWD
(
args
)...);
if
(
lineBreak
)
{
out
<<
std
::
endl
;
}
#endif
if
(
Environment
::
mpiSize
()
>
1
&&
Environment
::
mpiRank
()
==
0
)
fmt
::
print
(
out
,
"[0] "
+
str
,
FWD
(
args
)...);
else
if
(
Environment
::
mpiSize
()
==
1
)
fmt
::
print
(
out
,
str
,
FWD
(
args
)...);
return
out
;
#endif
}
}
// end namespace Impl
...
...
@@ -85,9 +95,17 @@ namespace AMDiS
* ```
**/
template
<
class
...
Args
>
void
msg
(
Args
&&
...
args
)
void
msg
(
std
::
string
const
&
str
,
Args
&&
...
args
)
{
Impl
::
msg
(
std
::
cout
,
str
+
"
\n
"
,
FWD
(
args
)...);
}
/// prints a message, if Environment::infoLevel() >= noInfoLevel
template
<
class
...
Args
>
void
info
(
int
noInfoLevel
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
Impl
::
msg
(
std
::
cout
,
true
,
FWD
(
args
)...);
if
(
int
(
AMDIS_INFO_LEVEL
)
>=
noInfoLevel
)
Impl
::
msg
(
std
::
cout
,
str
+
"
\n
"
,
FWD
(
args
)...);
}
...
...
@@ -99,11 +117,20 @@ namespace AMDiS
* ```
**/
template
<
class
...
Args
>
void
msg_
(
Args
&&
...
args
)
void
msg_
(
std
::
string
const
&
str
,
Args
&&
...
args
)
{
Impl
::
msg
(
std
::
cout
,
false
,
FWD
(
args
)...);
Impl
::
msg
(
std
::
cout
,
str
,
FWD
(
args
)...);
}
/// prints a message, if Environment::infoLevel() >= noInfoLevel
template
<
class
...
Args
>
void
info_
(
int
noInfoLevel
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
if
(
int
(
AMDIS_INFO_LEVEL
)
>=
noInfoLevel
)
Impl
::
msg
(
std
::
cout
,
str
,
FWD
(
args
)...);
}
/// \brief print a message and exit
/**
...
...
@@ -112,17 +139,13 @@ namespace AMDiS
* type \ref std::runtime_Error is thrown.
**/
template
<
class
...
Args
>
void
error_exit
(
Args
&&
...
args
)
void
error_exit
(
std
::
string
const
&
str
,
Args
&&
...
args
)
{
#ifdef AMDIS_NO_THROW
Impl
::
msg
(
std
::
cerr
<<
"ERROR: "
,
true
,
FWD
(
args
)...);
#ifndef NDEBUG
assert
(
false
);
#else
std
::
exit
(
EXIT_FAILURE
);
#endif
Impl
::
msg_all
(
std
::
cerr
,
"ERROR: "
+
str
+
"
\n
"
,
FWD
(
args
)...);
std
::
abort
();
#else
throw
std
::
runtime_error
(
std
::
string
(
"ERROR: "
)
+
fmt
::
format
(
FWD
(
args
)...));
throw
std
::
runtime_error
(
std
::
string
(
"ERROR: "
)
+
fmt
::
format
(
str
,
FWD
(
args
)...));
#endif
}
...
...
@@ -137,16 +160,16 @@ namespace AMDiS
* \p condition argument.
**/
template
<
class
...
Args
>
void
test_exit
(
bool
condition
,
Args
&&
...
args
)
void
test_exit
(
bool
condition
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
if
(
!
condition
)
{
error_exit
(
FWD
(
args
)...);
}
if
(
!
condition
)
{
error_exit
(
str
,
FWD
(
args
)...);
}
}
template
<
class
...
Args
>
void
warning
(
Args
&&
...
args
)
void
warning
(
std
::
string
const
&
str
,
Args
&&
...
args
)
{
Impl
::
msg
(
std
::
cout
<<
"WARNING: "
,
true
,
FWD
(
args
)...);
Impl
::
msg
(
std
::
cout
,
"WARNING: "
+
str
+
"
\n
"
,
FWD
(
args
)...);
}
...
...
@@ -157,9 +180,9 @@ namespace AMDiS
* string "WARNING".
**/
template
<
class
...
Args
>
void
test_warning
(
bool
condition
,
Args
&&
...
args
)
void
test_warning
(
bool
condition
,
std
::
string
const
&
str
,
Args
&&
...
args
)
{
if
(
!
condition
)
{
warning
(
FWD
(
args
)...);
}
if
(
!
condition
)
{
warning
(
str
,
FWD
(
args
)...);
}
}
...
...
@@ -191,4 +214,27 @@ namespace AMDiS
void
test_exit_dbg
(
bool
,
Args
&&
...)
{}
#endif
template
<
class
Vector
>
void
print_vec
(
std
::
string
prefix
,
Vector
const
&
vec
)
{
std
::
string
row_prefix
=
"["
+
std
::
to_string
(
Environment
::
mpiRank
())
+
"] "
;
for
(
int
r
=
0
;
r
<
Environment
::
mpiSize
();
++
r
)
{
if
(
r
==
Environment
::
mpiRank
())
{
std
::
cout
<<
row_prefix
<<
prefix
<<
": "
;
if
(
vec
.
size
()
==
0
)
{
std
::
cout
<<
"{}"
<<
std
::
endl
;
continue
;
}
std
::
cout
<<
"{"
<<
vec
[
0
];
for
(
std
::
size_t
i
=
1
;
i
<
vec
.
size
();
++
i
)
std
::
cout
<<
", "
<<
vec
[
i
];
std
::
cout
<<
"}"
<<
std
::
endl
;
}
#if HAVE_MPI
MPI_Barrier
(
Environment
::
comm
());
#endif
}
}
}
// end namespace AMDiS
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