![]() |
Rosetta
2020.50
|
A manager that maintains a threadpool and handles requests for threads for multithreaded execution of functions. This allows multithreading at many different levels in the Rosetta library hierarchy, from job-level parallel execution down to parallel computation of a score, gradient vector, or interaction graph. More...
#include <RosettaThreadManager.hh>
Public Member Functions | |
void | do_work_vector_in_threads (utility::vector1< RosettaThreadFunction > const &vector_of_work, platform::Size const requested_thread_count, RosettaThreadAssignmentInfo &thread_assignment) |
BASIC API THAT SHOULD BE USED IN MOST CIRCUMSTANCES. Given a vector of functions that were bundled with their arguments with std::bind, each of which can be executed in any order and each of which is safe to execute in parallel with any other, run all of these in threads. More... | |
void | do_work_vector_in_threads_no_locking (utility::vector1< RosettaThreadFunction > const &vector_of_work, platform::Size const requested_thread_count, RosettaThreadAssignmentInfo &thread_assignment) |
VARIANT BASIC API THAT SHOULD BE USED FOR WORK VECTORS OF NEAR-EQUAL SIZED CHUNKS WHERE THE CHUNKS ARE SMALL. Given a vector of functions that were bundled with their arguments with std::bind, each of which can be executed in any order and each of which is safe to execute in parallel with any other, run all of these in threads. More... | |
void | do_multistage_work_vector_in_threads (utility::vector1< utility::vector1< RosettaThreadFunction > > const &multistage_vector_of_work, platform::Size const requested_thread_count, RosettaThreadAssignmentInfo &thread_assignment) |
VARIANT BASIC API THAT SHOULD BE USED WHERE THE BASIC API CAN'T BE USED. Given a vector of vectors of functions that were bundled with their arguments with std::bind, run all of these in threads. In this case, the bundled functions are in groups, where the individual functions within a group can run in any order (and are safe to run concurrently), but the groups must be run sequentially. This is useful when, for example, you have a bunch of calculations to do, and then some finalization tasks to do after the calculations are done, and you don't want to re-request threads. More... | |
void | run_function_in_threads (RosettaThreadFunction &function_to_execute, platform::Size const requested_thread_count, RosettaThreadManagerAdvancedAPIKey const &key, RosettaThreadAssignmentInfo &thread_assignment) |
ADVANCED API THAT SHOULD NOT BE USED IN MOST CIRCUMSTANCES. Given a function that was bundled with its arguments with std::bind, run it in many threads. This calls RosettaThreadPool::run_function_in_threads for the already-running thread pool. If the thread pool has not been created, it first creates it by calling create_thread_pool(). IF YOU DECIDE TO USE THE ADVANCED API, YOU MUST: More... | |
platform::Size | get_rosetta_thread_index () const |
Get the Rosetta thread index. More... | |
![]() | |
SingletonBase () | |
public constructor (the derived class must have a private constructor, of course). More... | |
Static Public Member Functions | |
static platform::Size | total_threads () |
Get the total number of threads that have been launched or will be launched. More... | |
![]() | |
static RosettaThreadManager * | get_instance () |
Safely instantiate a singleton class in a (possibly) multithreaded context. More... | |
Private Member Functions | |
RosettaThreadManager () | |
Empty constructor. More... | |
RosettaThreadManager (RosettaThreadManager const &)=delete | |
Copy constructor – explicitly deleted. More... | |
RosettaThreadManager | operator= (RosettaThreadManager const &)=delete |
Assignment operator – explicitly deleted. More... | |
~RosettaThreadManager () | |
Destructor. Non-empty, since threads must be spun down. More... | |
Friends | |
class | utility::SingletonBase< RosettaThreadManager > |
A manager that maintains a threadpool and handles requests for threads for multithreaded execution of functions. This allows multithreading at many different levels in the Rosetta library hierarchy, from job-level parallel execution down to parallel computation of a score, gradient vector, or interaction graph.
|
private |
Empty constructor.
|
privatedelete |
Copy constructor – explicitly deleted.
|
private |
Destructor. Non-empty, since threads must be spun down.
void basic::thread_manager::RosettaThreadManager::do_multistage_work_vector_in_threads | ( | utility::vector1< utility::vector1< RosettaThreadFunction > > const & | multistage_vector_of_work, |
platform::Size const | requested_thread_count, | ||
RosettaThreadAssignmentInfo & | thread_assignment | ||
) |
VARIANT BASIC API THAT SHOULD BE USED WHERE THE BASIC API CAN'T BE USED. Given a vector of vectors of functions that were bundled with their arguments with std::bind, run all of these in threads. In this case, the bundled functions are in groups, where the individual functions within a group can run in any order (and are safe to run concurrently), but the groups must be run sequentially. This is useful when, for example, you have a bunch of calculations to do, and then some finalization tasks to do after the calculations are done, and you don't want to re-request threads.
The bundled functions should be atomistic pieces of work. They should be bundled with their arguments with std::bind, and the arguments should include the place to store output (i.e. they should return void). These functions should not handle any mutexes themselves, but should ensure that they are operating only on memory locations that no other functions in the vector are operating on.
References debug_assert, basic::options::OptionKeys::frags::j, min(), run_function_in_threads(), runtime_assert_string_msg, amino_acids::size, basic::TR, and basic::Tracer::Warning.
void basic::thread_manager::RosettaThreadManager::do_work_vector_in_threads | ( | utility::vector1< RosettaThreadFunction > const & | vector_of_work, |
platform::Size const | requested_thread_count, | ||
RosettaThreadAssignmentInfo & | thread_assignment | ||
) |
BASIC API THAT SHOULD BE USED IN MOST CIRCUMSTANCES. Given a vector of functions that were bundled with their arguments with std::bind, each of which can be executed in any order and each of which is safe to execute in parallel with any other, run all of these in threads.
The bundled functions should be atomistic pieces of work. They should be bundled with their arguments with std::bind, and the arguments should include the place to store output (i.e. they should return void). These functions should not handle any mutexes themselves, but should ensure that they are operating only on memory locations that no other functions in the vector are operating on.
The bundled functions should be atomistic pieces of work. They should be bundled with their arguments with std::bind, and the arguments should include the place to store output (i.e. they should return void). These functions should not handle any mutexes themselves, but should ensure that they are operating only on memory locations that no other functions in the vector are operating on.
References min(), run_function_in_threads(), runtime_assert_string_msg, basic::TR, and basic::Tracer::Warning.
void basic::thread_manager::RosettaThreadManager::do_work_vector_in_threads_no_locking | ( | utility::vector1< RosettaThreadFunction > const & | vector_of_work, |
platform::Size const | requested_thread_count, | ||
RosettaThreadAssignmentInfo & | thread_assignment | ||
) |
VARIANT BASIC API THAT SHOULD BE USED FOR WORK VECTORS OF NEAR-EQUAL SIZED CHUNKS WHERE THE CHUNKS ARE SMALL. Given a vector of functions that were bundled with their arguments with std::bind, each of which can be executed in any order and each of which is safe to execute in parallel with any other, run all of these in threads.
The bundled functions should be atomistic pieces of work. They should be bundled with their arguments with std::bind, and the arguments should include the place to store output (i.e. they should return void). These functions should not handle any mutexes themselves, but should ensure that they are operating only on memory locations that no other functions in the vector are operating on.
References min(), run_function_in_threads(), and runtime_assert_string_msg.
platform::Size basic::thread_manager::RosettaThreadManager::get_rosetta_thread_index | ( | ) | const |
Get the Rosetta thread index.
References utility::io::oc::cerr, and MAX_THREAD_INDEX_WARNINGS.
|
privatedelete |
Assignment operator – explicitly deleted.
void basic::thread_manager::RosettaThreadManager::run_function_in_threads | ( | RosettaThreadFunction & | function_to_execute, |
platform::Size const | requested_thread_count, | ||
RosettaThreadManagerAdvancedAPIKey const & | key, | ||
RosettaThreadAssignmentInfo & | thread_assignment | ||
) |
ADVANCED API THAT SHOULD NOT BE USED IN MOST CIRCUMSTANCES. Given a function that was bundled with its arguments with std::bind, run it in many threads. This calls RosettaThreadPool::run_function_in_threads for the already-running thread pool. If the thread pool has not been created, it first creates it by calling create_thread_pool(). IF YOU DECIDE TO USE THE ADVANCED API, YOU MUST:
The function is assigned to as many threads as the RosettaThreadPool decides to assign it to, always including the thread from which the request originates. It is guaranteed to run in 1 <= actual_thread_count <= requested_thread_count threads. After assigning the function to up to (requsted_thread_count - 1) other threads, the function executes in the current thread, then the current thread blocks until the assigned threads report that they are idle. All of this is handled by the RosettaThreadPool class (or its derived classes, which may have) different logic for assigning thread requests to threads).
References runtime_assert_string_msg.
Referenced by do_multistage_work_vector_in_threads(), do_work_vector_in_threads(), and do_work_vector_in_threads_no_locking().
|
inlinestatic |
Get the total number of threads that have been launched or will be launched.
This corresponds to the -multithreading:total_threads option, but it does not access the options system repatedly.d
References utility::SingletonBase< RosettaThreadManagerInitializationTracker >::get_instance().
|
friend |