Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
L
load_leveller
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lukas Weber
load_leveller
Commits
c43f9386
Commit
c43f9386
authored
Dec 03, 2019
by
Lukas Weber
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize observable::add/add support for many containers
parent
07ab802f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
31 deletions
+5
-31
src/observable.h
src/observable.h
+5
-31
No files found.
src/observable.h
View file @
c43f9386
...
...
@@ -16,10 +16,10 @@ public:
const
std
::
string
&
name
()
const
;
template
<
class
T
>
void
add
(
T
);
auto
add
(
T
val
)
->
decltype
(
val
+
val
,
void
()
);
template
<
class
T
>
void
add
(
const
std
::
vector
<
T
>
&
);
auto
add
(
const
T
&
val
)
->
decltype
(
val
[
0
],
void
()
);
template
<
class
T
>
void
add
(
const
std
::
valarray
<
T
>
&
);
...
...
@@ -34,7 +34,6 @@ public:
// switch copy with target rank.
// useful for parallel tempering mode
void
mpi_sendrecv
(
int
target_rank
);
private:
static
const
size_t
initial_bin_length
=
1000
;
...
...
@@ -48,38 +47,13 @@ private:
};
template
<
class
T
>
void
observable
::
add
(
T
val
)
{
std
::
vector
<
T
>
v
=
{
val
};
add
(
v
);
auto
observable
::
add
(
T
val
)
->
decltype
(
val
+
val
,
void
())
{
add
(
std
::
array
<
T
,
1
>
{
val
});
}
template
<
class
T
>
void
observable
::
add
(
const
std
::
vector
<
T
>
&
val
)
{
if
(
vector_length_
!=
val
.
size
())
{
throw
std
::
runtime_error
{
fmt
::
format
(
"observable::add: added vector has unexpected size ({}). Observable was "
"initialized with vector length ({})"
,
val
.
size
(),
vector_length_
)};
}
for
(
size_t
j
=
0
;
j
<
vector_length_
;
++
j
)
samples_
[
j
+
current_bin_
*
vector_length_
]
+=
static_cast
<
double
>
(
val
[
j
]);
current_bin_filling_
++
;
if
(
current_bin_filling_
==
bin_length_
)
{
// need to start a new bin next time
if
(
bin_length_
>
1
)
{
for
(
size_t
j
=
0
;
j
<
vector_length_
;
++
j
)
{
samples_
[
current_bin_
*
vector_length_
+
j
]
/=
bin_length_
;
}
}
current_bin_
++
;
samples_
.
resize
((
current_bin_
+
1
)
*
vector_length_
);
current_bin_filling_
=
0
;
}
}
template
<
class
T
>
void
observable
::
add
(
const
std
::
valarray
<
T
>
&
val
)
{
auto
observable
::
add
(
const
T
&
val
)
->
decltype
(
val
[
0
],
void
()
)
{
if
(
vector_length_
!=
val
.
size
())
{
throw
std
::
runtime_error
{
fmt
::
format
(
"observable::add: added vector has unexpected size ({}). Observable was "
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment