Skip to content

Instantly share code, notes, and snippets.

@jonathan-beard
Created July 10, 2018 17:34
Show Gist options
  • Save jonathan-beard/e2ac9ab2da2c9e50771898819c2e0166 to your computer and use it in GitHub Desktop.
Save jonathan-beard/e2ac9ab2da2c9e50771898819c2e0166 to your computer and use it in GitHub Desktop.
template< class partition =
/**
* a bit hacky, yes, but enables you to inject
* the partitioner...if you'd like while keeping
* the default selection somewhat optimal (i.e.,
* enabling thread pinning if available by default)
*/
#ifdef __linux
#if USE_PARTITION
partition_scotch
#else
//partition_basic /** no scotch, simple affinity assign **/
partition_dummy
#endif
#else /** OS X, WIN64 **/
partition_dummy
#endif
, /** comma for above **/
class scheduler =
#ifdef USEQTHREADS
pool_schedule
#else
simple_schedule
#endif
,
class allocator = dynalloc,
class parallelism_monitor = basic_parallel >
void exe()
{
{
auto &container( all_kernels.acquire() );
for( auto * const submap : sub_maps )
{
auto &subcontainer( submap->all_kernels.acquire() );
container.insert( subcontainer.begin(),
subcontainer.end() );
submap->all_kernels.release();
}
all_kernels.release();
}
/** check types, ensure all are linked **/
checkEdges();
partition pt;
pt.partition( all_kernels );
/** adds in split/join kernels **/
//enableDuplication( source_kernels, all_kernels );
volatile bool exit_alloc( false );
allocator alloc( (*this), exit_alloc );
/** launch allocator in a thread **/
std::thread mem_thread( [&](){
alloc.run();
});
try
{
alloc.waitTillReady();
}
catch( std::exception &ex )
{
std::cerr << "caught here\n";
}
scheduler sched( (*this) );
sched.init();
/** launch scheduler in thread **/
std::thread sched_thread( [&](){
sched.start();
});
volatile bool exit_para( false );
/** launch parallelism monitor **/
parallelism_monitor pm( (*this) /** ref to this **/,
alloc /** allocator **/,
sched /** scheduler **/,
exit_para /** exit parameter **/);
std::thread parallel_mon( [&](){
pm.start();
});
/** join scheduler first **/
sched_thread.join();
/** scheduler done, cleanup alloc **/
exit_alloc = true;
mem_thread.join();
/** no more need to duplicate kernels **/
exit_para = true;
parallel_mon.join();
/** all fifo's deallocated when alloc goes out of scope **/
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment