Skip to content

Cannot update ADFun in parallel mode. #218

Answered by bradbell
khaiyichin asked this question in Q&A
Discussion options

You must be logged in to vote

The problem is that the default constructor

Dummy() { SetupADFun(); }

Is getting called by thread zero at line

 std::vector<Dummy> d_obj_vec(5); // create 5 dummy objects

But the corresponding destructors are getting called inside the omp parallel for loop.
The Code will work if you change the default constructor to

Dummy() { }

And move the line

d_obj_vec[i].SetupADFun();

to the beginning of the parallel for loop.

You may run into a problem if the same parallel index 'i' uses different threads for different values of the 'loop' index.

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by bradbell
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #217 on October 25, 2024 21:53.