Skip to content

Commit

Permalink
Color filling function, part 1
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Mercier <[email protected]>
  • Loading branch information
GuillaumeMercier committed Sep 17, 2024
1 parent 70f95bc commit fe616d2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
11 changes: 10 additions & 1 deletion include/quo-vadis-pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
49 changes: 44 additions & 5 deletions src/quo-vadis-pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

/*
Expand Down
16 changes: 15 additions & 1 deletion tests/test-pthread-split.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fe616d2

Please sign in to comment.