diff --git a/include/quo-vadis-pthread.h b/include/quo-vadis-pthread.h index a54399d..98db0b8 100644 --- a/include/quo-vadis-pthread.h +++ b/include/quo-vadis-pthread.h @@ -30,6 +30,13 @@ extern "C" { /** * Mapping policies types. */ +// Intel policies (KMP_AFFINITY) are : +// - disabled: prevents the runtime library from making any affinity-related +// system calls (to avoid interference with other platform affinity mechanisms). +// - compact: threads are placed as close together as possible. +// - scatter: threads are distributed as evenly as possible across the entire system. +// (opposite of compact). +// - explicit: threads are placed according to a list of OS proc IDs (required) typedef enum qv_policy_s { QV_POLICY_PACKED = 1, QV_POLICY_COMPACT = 1, @@ -88,7 +95,9 @@ int qv_pthread_colors_fill( int *color_array, int array_size, - qv_policy_t policy + qv_policy_t policy, + int stride, + int npieces ); #ifdef __cplusplus diff --git a/src/quo-vadis-pthread.cc b/src/quo-vadis-pthread.cc index 4ca1e59..a7a288f 100644 --- a/src/quo-vadis-pthread.cc +++ b/src/quo-vadis-pthread.cc @@ -24,6 +24,7 @@ #include "qvi-scope.h" #include "qvi-utils.h" + struct qvi_pthread_args_s { qv_scope_t *scope = nullptr; qvi_pthread_routine_fun_ptr_t th_routine = nullptr; @@ -137,12 +138,50 @@ qv_pthread_scopes_free( int qv_pthread_colors_fill( - int *,//color_array, - int, // array_size, - qv_policy_t //policy + int *color_array, + int array_size, + qv_policy_t policy, + int stride, + int npieces ){ - //TODO(GM) implement - return QV_ERR_NOT_SUPPORTED; + int rc = QV_SUCCESS; + + switch(policy){ + case QV_POLICY_SPREAD: + { + break; + } + + case QV_POLICY_DISTRIBUTE: + //case QV_POLICY_ALTERNATE: + //case QV_POLICY_CORESFIRST: + { + break; + } + + case QV_POLICY_SCATTER: + { + break; + } + + case QV_POLICY_CHOOSE: + { + break; + } + + case QV_POLICY_PACKED: + //case QV_POLICY_COMPACT: + //case QV_POLICY_CLOSE: + default: + { + for(int idx = 0 ; idx < array_size ; idx++){ + color_array[idx] = (idx+idx*(stride-1))%(npieces); + } + break; + } + } + + return rc; } /* diff --git a/tests/test-pthread-split.c b/tests/test-pthread-split.c index 0625ab4..a512fb5 100644 --- a/tests/test-pthread-split.c +++ b/tests/test-pthread-split.c @@ -104,10 +104,17 @@ main(void) fprintf(stdout,"[%d] ====== Testing thread_scope_split (number of threads : %i)\n", tid, nthreads); int colors[nthreads]; + + /* for (int i = 0 ; i < nthreads ; i++) { colors[i] = i % npieces; } - + */ + rc = qv_pthread_colors_fill(colors, nthreads, QV_POLICY_PACKED, 1, npieces); + if (rc != QV_SUCCESS) { + ers = "qv_pthread_colors_fill() failed"; + qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); + } qv_scope_t **th_scopes = NULL; rc = qv_pthread_scope_split( @@ -159,9 +166,16 @@ main(void) fprintf(stdout,"[%d] ====== Testing thread_scope_split_at (number of threads : %i)\n", tid, nthreads); int colors2[nthreads]; + /* for (int i = 0 ; i < nthreads ; i++) { colors2[i] = i % ncores; } + */ + rc = qv_pthread_colors_fill(colors2, nthreads, QV_POLICY_PACKED, 1, ncores); + if (rc != QV_SUCCESS) { + ers = "qv_pthread_colors_fill() failed"; + qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc)); + } rc = qv_pthread_scope_split_at( mpi_scope, QV_HW_OBJ_CORE, colors2, nthreads, &th_scopes