Skip to content

Commit

Permalink
Modified pthread example (#67)
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Mercier <[email protected]>
  • Loading branch information
GuillaumeMercier authored Jul 18, 2023
1 parent 4c4df59 commit 038422c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions tests/test-mpi-pthreads-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,35 @@
typedef struct {
int wrank;
int rc;
void *(*work_func)(void *);
void *func_arg;
qv_thread_args_t th_args;
} args_t;


void *thread_work(void *arg)
{
qv_thread_args_t th_args = ((args_t *)arg)->th_args;
void *ret __attribute__((unused)) = NULL;

printf("[%d][%d] Binding to PUS \n", ((args_t *)arg)->wrank, th_args.th_id);

/* Apply layout and bind thread */
((args_t *)arg)->rc = qv_thread_layout_apply(th_args);

/* do some work now */
/* do the real work now */
ret = ((args_t *)arg)->work_func(((args_t *)arg)->func_arg);

pthread_exit(NULL);
}

void *work_example(void *arg)
{
int val = *((int *)arg);
fprintf(stdout,"========= Hi there! %i\n",val);
return NULL;
}

int
main(void)
{
Expand Down Expand Up @@ -157,9 +170,12 @@ main(void)

pthread_t *tid = malloc(num_threads*sizeof(pthread_t));
args_t *args = malloc(num_threads*sizeof(args_t));

int value = 101;

for(int i = 0 ; i < num_threads ; i++) {
args[i].wrank = wrank;
args[i].wrank = wrank;
args[i].work_func = work_example;
args[i].func_arg = &value;
rc = qv_thread_args_set(mpi_ctx,mpi_numa_scope,thread_layout,i,num_threads,&(args[i].th_args));
if (rc != QV_SUCCESS) {
ers = "qv_thread_args_set() failed";
Expand Down Expand Up @@ -190,7 +206,9 @@ main(void)
args = malloc(num_threads*sizeof(args_t));

for(int i = 0 ; i < num_threads ; i++) {
args[i].wrank = wrank;
args[i].wrank = wrank;
args[i].work_func = work_example;
args[i].func_arg = &value;
rc = qv_thread_args_set(mpi_ctx,mpi_numa_scope,thread_layout,i,num_threads,&(args[i].th_args));
if (rc != QV_SUCCESS) {
ers = "qv_thread_args_set() failed";
Expand Down

0 comments on commit 038422c

Please sign in to comment.