Skip to content

Commit

Permalink
Merge pull request #637 from abouteiller/bugfix/dtd_destruct_not_syme…
Browse files Browse the repository at this point in the history
…tric

bugfix: dtd taskpool destructor should work symetric to contructor
  • Loading branch information
abouteiller authored Mar 1, 2024
2 parents 391fed8 + 48ed5da commit 545dbb5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 37 deletions.
79 changes: 42 additions & 37 deletions parsec/interfaces/dtd/insert_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,36 @@ parsec_dtd_taskpool_destructor(parsec_dtd_taskpool_t *tp)
{
uint32_t i;

parsec_dtd_data_collection_fini(&tp->new_tile_dc);
parsec_data_collection_destroy(&tp->new_tile_dc);

#if defined(PARSEC_PROF_TRACE)
free((void *)tp->super.profiling_array);
#endif /* defined(PARSEC_PROF_TRACE) */

parsec_context_remove_taskpool(&tp->super);
if(NULL != tp->super.context) { /* Initialized only if taskpool startup hook ran */
/* The taskpool is just out of a wait and is ready to receive new tasks at this time, so it has a termination detector */
assert(NULL != tp->super.tdm.module);
/* The taskpool is NOT READY, because every time we leave wait(), we reinitialize the termination detector. */
assert( tp->super.tdm.module->taskpool_state(&tp->super) == PARSEC_TERM_TP_NOT_READY );
/* But there should be 0 event on this taskpool at this time */
assert( tp->super.nb_pending_actions == 0 && tp->super.nb_tasks == 0);
/* So, we can terminate this termination detector by stating we are ready */
tp->super.tdm.module->taskpool_ready(&tp->super);

parsec_dtd_data_collection_fini(&tp->new_tile_dc);
parsec_data_collection_destroy(&tp->new_tile_dc);

parsec_context_remove_taskpool(&tp->super);

/* Unregister the taskpool from the devices */
for( i = 0; i < parsec_nb_devices; i++ ) {
parsec_device_module_t *device = parsec_mca_device_get(i);
if( !(tp->super.devices_index_mask & (1 << device->device_index)))
continue;
tp->super.devices_index_mask &= ~(1 << device->device_index);
if((NULL == device) || (NULL == device->taskpool_unregister))
continue;
(void)device->taskpool_unregister(device, &tp->super);
}
assert(0 == tp->super.devices_index_mask);

/* The taskpool is just out of a wait and is ready to receive new tasks at this time, so it has a termination detector */
assert(NULL != tp->super.tdm.module);
/* The taskpool is NOT READY, because every time we leave wait(), we reinitialize the termination detector. */
assert( tp->super.tdm.module->taskpool_state(&tp->super) == PARSEC_TERM_TP_NOT_READY );
/* But there should be 0 event on this taskpool at this time */
assert( tp->super.nb_pending_actions == 0 && tp->super.nb_tasks == 0);
/* So, we can terminate this termination detector by stating we are ready */
tp->super.tdm.module->taskpool_ready(&tp->super);
/* taskpool_unregister will unmonitor this taskpool */
parsec_taskpool_unregister( (parsec_taskpool_t*)tp );
/* taskpool_unregister will unmonitor this taskpool */
parsec_taskpool_unregister( (parsec_taskpool_t*)tp );
}

/* Destroy the data repositories for this object */
for (i = 0; i < PARSEC_DTD_NB_TASK_CLASSES; i++) {
Expand All @@ -394,27 +405,19 @@ parsec_dtd_taskpool_destructor(parsec_dtd_taskpool_t *tp)
tp->super.dependencies_array[i] = NULL;
}

free(tp->super.dependencies_array);
free(tp->super.taskpool_name);
tp->super.dependencies_array = NULL;

/* Unregister the taskpool from the devices */
for( i = 0; i < parsec_nb_devices; i++ ) {
parsec_device_module_t *device = parsec_mca_device_get(i);
if( !(tp->super.devices_index_mask & (1 << device->device_index)))
continue;
tp->super.devices_index_mask &= ~(1 << device->device_index);
if((NULL == device) || (NULL == device->taskpool_unregister))
continue;
(void)device->taskpool_unregister(device, &tp->super);
}
assert(0 == tp->super.devices_index_mask);
free(tp->super.task_classes_array);

/* dtd_taskpool specific */
parsec_mempool_destruct(tp->hash_table_bucket_mempool);
free(tp->hash_table_bucket_mempool);

#if defined(PARSEC_PROF_TRACE)
free((void *)tp->super.profiling_array);
#endif /* defined(PARSEC_PROF_TRACE) */

free(tp->super.taskpool_name);
free(tp->super.dependencies_array);
tp->super.dependencies_array = NULL;
free(tp->super.task_classes_array);

parsec_hash_table_fini(tp->task_hash_table);
PARSEC_OBJ_RELEASE(tp->task_hash_table);

Expand Down Expand Up @@ -1251,8 +1254,10 @@ parsec_dtd_data_collection_init(parsec_data_collection_t *dc)
void
parsec_dtd_data_collection_fini(parsec_data_collection_t *dc)
{
parsec_hash_table_fini(dc->tile_h_table);
PARSEC_OBJ_RELEASE(dc->tile_h_table);
if(NULL != dc->tile_h_table) { /* not initialized before taskpool_start */
parsec_hash_table_fini(dc->tile_h_table);
PARSEC_OBJ_RELEASE(dc->tile_h_table);
}
parsec_dc_unregister_id(dc->dc_id);
}

Expand Down
1 change: 1 addition & 0 deletions tests/dsl/dtd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
link_libraries(tests_common)

parsec_addtest_executable(C dtd_test_empty SOURCES dtd_test_empty.c)
parsec_addtest_executable(C dtd_test_pingpong SOURCES dtd_test_pingpong.c)
parsec_addtest_executable(C dtd_test_task_generation SOURCES dtd_test_task_generation.c)
parsec_addtest_executable(C dtd_test_war SOURCES dtd_test_war.c)
Expand Down
2 changes: 2 additions & 0 deletions tests/dsl/dtd/Testings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Shared Memory Testings
#
parsec_addtest_cmd(dsl/dtd/empty ${SHM_TEST_CMD_LIST} dsl/dtd/dtd_test_empty)
parsec_addtest_cmd(dsl/dtd/task_generation ${SHM_TEST_CMD_LIST} dsl/dtd/dtd_test_task_generation)
parsec_addtest_cmd(dsl/dtd/task_inserting_task ${SHM_TEST_CMD_LIST} dsl/dtd/dtd_test_task_inserting_task)
parsec_addtest_cmd(dsl/dtd/task_insertion ${SHM_TEST_CMD_LIST} dsl/dtd/dtd_test_task_insertion)
Expand All @@ -15,6 +16,7 @@ endif(PARSEC_HAVE_CUDA AND CMAKE_CUDA_COMPILER)
# Distributed Memory Testings
#
if( MPI_C_FOUND )
parsec_addtest_cmd(dsl/dtd/empty:mp ${MPI_TEST_CMD_LIST} 2 dsl/dtd/dtd_test_empty)
parsec_addtest_cmd(dsl/dtd/pingpong:mp ${MPI_TEST_CMD_LIST} 2 dsl/dtd/dtd_test_pingpong)
parsec_addtest_cmd(dsl/dtd/task_inserting_task:mp ${MPI_TEST_CMD_LIST} 4 dsl/dtd/dtd_test_task_inserting_task)
parsec_addtest_cmd(dsl/dtd/task_insertion:mp ${MPI_TEST_CMD_LIST} 4 dsl/dtd/dtd_test_task_insertion)
Expand Down
26 changes: 26 additions & 0 deletions tests/dsl/dtd/dtd_test_empty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "parsec.h"
#include <mpi.h>

int main(int argc, char **argv)
{
parsec_context_t* parsec;
int rank = 0, world = 1;

#if defined(PARSEC_HAVE_MPI)
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided);
MPI_Comm_size(MPI_COMM_WORLD, &world);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#endif

parsec = parsec_init( -1, &argc, &argv );
parsec_taskpool_t *dtd_tp = parsec_dtd_taskpool_new();
parsec_taskpool_free( dtd_tp );
parsec_fini(&parsec);

#ifdef PARSEC_HAVE_MPI
MPI_Finalize();
#endif

return 0;
}

0 comments on commit 545dbb5

Please sign in to comment.