Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Frida
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coenen, Joachim
Frida
Commits
9ebd889a
Commit
9ebd889a
authored
9 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
replace OpenMP by C++ threads;
this introduces an OS dependency (pthread) into lib/CmaeLists.txt.
parent
38962fff
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pub/CMakeLists.txt
+1
-14
1 addition, 14 deletions
pub/CMakeLists.txt
pub/lib/fit.cpp
+37
-20
37 additions, 20 deletions
pub/lib/fit.cpp
with
38 additions
and
34 deletions
pub/CMakeLists.txt
+
1
−
14
View file @
9ebd889a
...
...
@@ -19,22 +19,9 @@ enable_testing()
#option(FRIDA_MAN "Build a user manual" OFF)
#option(BUILD_DEBIAN "Build a debian package" OFF)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -g -pedantic -Wall -Wno-sign-compare -Wno-unused-result -Wno-parentheses -Werror"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11 -g -pedantic -Wall -Wno-sign-compare -Wno-unused-result -Wno-parentheses
-Wno-unknown-pragmas
-Werror"
)
# to use C99 _Complex, add -fext-numeric-literals to CXX_FLAGS
option
(
openmp
"Enable multithreading with OpenMP"
ON
)
if
(
openmp
)
find_package
(
OpenMP
)
if
(
OPENMP_FOUND
)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
${
OpenMP_C_FLAGS
}
"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
${
OpenMP_CXX_FLAGS
}
"
)
endif
()
message
(
STATUS
"OpenMP: on"
)
else
()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-Wno-unknown-pragmas"
)
message
(
STATUS
"OpenMP: off"
)
endif
()
find_package
(
Boost REQUIRED
)
# used header-only modules: format algorithm
find_package
(
BISON REQUIRED
)
find_package
(
FLEX REQUIRED
)
...
...
This diff is collapsed.
Click to expand it.
pub/lib/fit.cpp
+
37
−
20
View file @
9ebd889a
...
...
@@ -9,9 +9,9 @@
#include
"defs.hpp"
#include
<functional>
#include
<thread>
#include
<boost/format.hpp>
#include
<omp.h>
#include
<lmmin.h>
#include
"../readplus/ask.hpp"
...
...
@@ -32,6 +32,26 @@ namespace NCurveFit {
void
fit_global
(
POlc
fc
,
ROld
fd
,
int
k
,
const
lm_control_struct
&
control
);
}
void
conditionally_parallel_for
(
bool
condition
,
int
niter
,
const
std
::
function
<
void
(
int
)
>&
exec
,
const
std
::
function
<
void
(
int
)
>&
report
)
{
if
(
condition
)
{
vector
<
std
::
thread
>
workers
;
for
(
int
i
=
0
;
i
<
niter
;
++
i
)
{
workers
.
push_back
(
std
::
thread
(
exec
,
i
)
);
}
for
(
int
i
=
0
;
i
<
niter
;
++
i
)
{
workers
[
i
].
join
();
report
(
i
);
}
}
else
{
for
(
int
i
=
0
;
i
<
niter
;
++
i
)
{
exec
(
i
);
report
(
i
);
}
}
}
//**************************************************************************************************
//* Fit tuning parameters
...
...
@@ -212,7 +232,7 @@ string NCurveFit::fit_one_spec( POlc fc, ROld fd, int k, int j, const lm_control
// Levenberg-Marquardt routine from library lmfit:
data
.
timeout
=
time
(
nullptr
)
+
omp_get_num_threads
()
*
maxtime
;
data
.
timeout
=
time
(
nullptr
)
+
std
::
thread
::
hardware_concurrency
()
*
maxtime
;
lm_status_struct
status
;
lmmin
(
npfree
,
&
(
Par
[
0
]),
nd
,
&
data
,
fit_evaluate
,
&
control
,
&
status
);
...
...
@@ -304,14 +324,15 @@ static void fit_evaluate_glo( const double* par, int m_dat, const void *data,
throw
S
(
"inconsistent number of free parameters"
);
bool
want_error
=
wt
==
COlc
::
_VAR
||
wt
==
COlc
::
_VARC
;
#pragma omp parallel for // if ( !NCurveFit::verbosity )
for
(
int
jj
=
0
;
jj
<
mydata
->
J2J
.
size
();
++
jj
)
{
compute_residues
(
fvec
,
mydata
->
Offset
[
jj
],
mydata
->
J2J
[
jj
],
fd
->
VS
(
mydata
->
J2J
[
jj
]),
fc
->
eval_curve
(
fd
->
VS
(
mydata
->
J2J
[
jj
])
->
x
,
mydata
->
k
,
mydata
->
J2J
[
jj
],
want_error
),
wt
);
}
conditionally_parallel_for
(
!
NCurveFit
::
verbosity
,
mydata
->
J2J
.
size
(),
[
&
](
int
jj
)
->
void
{
compute_residues
(
fvec
,
mydata
->
Offset
[
jj
],
mydata
->
J2J
[
jj
],
fd
->
VS
(
mydata
->
J2J
[
jj
]),
fc
->
eval_curve
(
fd
->
VS
(
mydata
->
J2J
[
jj
])
->
x
,
mydata
->
k
,
mydata
->
J2J
[
jj
],
want_error
),
wt
);
},
[
&
](
int
jj
)
->
void
{}
);
}
catch
(
string
&
s
)
{
cout
<<
"
\n
"
<<
s
<<
"
\n
"
;
*
userbreak
=
-
1
;
...
...
@@ -504,16 +525,12 @@ void NCurveFit::fit( bool _allow_slow_conv )
if
(
!
fc
->
VC
(
j
)
->
frozen
)
J
.
push_back
(
j
);
vector
<
string
>
out
(
J
.
size
(),
""
);
vector
<
std
::
thread
>
workers
;
for
(
int
jj
=
0
;
jj
<
J
.
size
();
++
jj
)
{
workers
.
push_back
(
std
::
thread
([
&
](
int
_jj
)
->
void
{
out
[
_jj
]
=
fit_one_spec
(
fc
,
fd
,
fiter
.
k
(),
J
[
_jj
],
control
)
+
"
\n
"
;
},
jj
)
);
}
for
(
int
jj
=
0
;
jj
<
J
.
size
();
++
jj
)
{
workers
[
jj
].
join
();
cout
<<
out
[
jj
];
}
conditionally_parallel_for
(
!
NCurveFit
::
verbosity
,
J
.
size
(),
[
&
](
int
_jj
)
->
void
{
out
[
_jj
]
=
fit_one_spec
(
fc
,
fd
,
fiter
.
k
(),
J
[
_jj
],
control
)
+
"
\n
"
;
},
[
&
](
int
_jj
)
->
void
{
cout
<<
out
[
_jj
];
}
);
}
// fit mode
}
// k
}
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