Skip to content

Commit

Permalink
master: openmp and bthread: parallel_setup(1, nullptr, nullptr) after…
Browse files Browse the repository at this point in the history
… multi-threading.
  • Loading branch information
bradbell committed Mar 14, 2024
1 parent bd6a54f commit 8de3bf3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions example/multi_thread/bthread/get_started.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ bool get_started(void)
//
// sequential_execution_
sequential_execution_ = true;
CppAD::thread_alloc::parallel_setup(1, nullptr, nullptr);
ok &= ! in_parallel();
//
// hold_memory
Expand Down
6 changes: 3 additions & 3 deletions example/multi_thread/openmp/get_started.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool get_started(void)
//
// parallel_setup
omp_set_num_threads( int(num_threads) );
assert( ! in_parallel() );
ok &= ! in_parallel();
CppAD::thread_alloc::parallel_setup(
num_threads, in_parallel, thread_number
);
Expand All @@ -144,8 +144,8 @@ bool get_started(void)
//
// hold_memory
// free memory for other threads before this (the master thread)
assert( ! in_parallel() );
assert( thread_number() == 0 );
CppAD::thread_alloc::parallel_setup(1, nullptr, nullptr);
ok &= ! in_parallel();
CppAD::thread_alloc::hold_memory(false);
for(size_t i = 1; i < num_threads; ++i)
CppAD::thread_alloc::free_available(i);
Expand Down
7 changes: 4 additions & 3 deletions example/multi_thread/pthread/get_started.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ namespace {
//
// phtread_setspecific, ok
if( thread_num != 0 )
rc = pthread_setspecific(thread_specific_key_, &thread_num);
ok &= rc == 0;
ok &= thread_number() == thread_num;
{ rc = pthread_setspecific(thread_specific_key_, &thread_num);
ok &= rc == 0;
ok &= thread_number() == thread_num;
}
//
// Jac
for(size_t j = j_begin; j < j_end; ++j)
Expand Down

0 comments on commit 8de3bf3

Please sign in to comment.