Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test PThread argument forwarding. #222

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 55 additions & 23 deletions tests/test-pthread-split.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@
#include "quo-vadis-pthread.h"
#include "qvi-test-common.h"

typedef struct {
qv_scope_t *scope;
int answer;
} thargs_t;

void *
thread_work(
void *arg
) {
char const *ers = NULL;
const pid_t tid = qvi_test_gettid();
qv_scope_t *scope = (qv_scope_t *)arg;
thargs_t *thargs = (thargs_t *)arg;

qv_scope_t *scope = thargs->scope;
if (thargs->answer != 42) {
ers = "user arguments not forwarded!";
qvi_test_panic("%s", ers);
}

char *binds = NULL;
int rc = qv_scope_bind_string(scope, QV_BIND_STRING_AS_LIST, &binds);
Expand All @@ -30,16 +41,15 @@ main(void)
{
char const *ers = NULL;
const pid_t tid = qvi_test_gettid();
MPI_Comm comm = MPI_COMM_WORLD;
int wrank, wsize;
int n_cores = 0;

int rc = MPI_Init(NULL, NULL);
if (rc != MPI_SUCCESS) {
ers = "MPI_Init() failed";
qvi_test_panic("%s (rc=%d)", ers, rc);
}

MPI_Comm comm = MPI_COMM_WORLD;
rc = MPI_Comm_size(comm, &wsize);
if (rc != MPI_SUCCESS) {
ers = "MPI_Comm_size() failed";
Expand All @@ -63,43 +73,53 @@ main(void)
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

rc = qv_scope_nobjs(mpi_scope, QV_HW_OBJ_CORE, &n_cores);
int ncores = 0;
rc = qv_scope_nobjs(mpi_scope, QV_HW_OBJ_CORE, &ncores);
if (rc != QV_SUCCESS) {
ers = "qv_scope_nobjs() failed";
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

//test qv_pthread_scope_split
int npieces = n_cores / 2;
int nthreads = n_cores;
int npieces = ncores / 2;
int nthreads = ncores;

fprintf(stdout,"[%d] ====== Testing thread_scope_split (number of threads : %i)\n", tid, nthreads);

int colors[nthreads];
for(int i = 0 ; i < nthreads ; i++) {
for (int i = 0 ; i < nthreads ; i++) {
colors[i] = i % npieces;
}

qv_scope_t **th_scopes = NULL;
rc = qv_pthread_scope_split(mpi_scope, npieces, colors, nthreads, &th_scopes);
rc = qv_pthread_scope_split(
mpi_scope, npieces, colors, nthreads, &th_scopes
);
if (rc != QV_SUCCESS) {
ers = "qv_pthread_scope_split() failed";
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

thargs_t thargs[nthreads];
for (int i = 0 ; i < nthreads; i ++) {
thargs[i].scope = th_scopes[i];
thargs[i].answer = 42;
}

pthread_t thid[nthreads];
pthread_attr_t *attr = NULL;

for (int i = 0 ; i < nthreads; i ++) {
//sleep(1);
if (qv_pthread_create(&thid[i], attr, thread_work, (void *)(th_scopes[i]), th_scopes[i]) != 0) {
perror("pthread_create() error");
exit(1);
const int ptrc = qv_pthread_create(
&thid[i], attr, thread_work, &thargs[i], th_scopes[i]
);
if (ptrc != 0) {
ers = "qv_pthread_create() failed";
qvi_test_panic("%s (rc=%s)", ers, strerror(rc));
}
}

void *ret;
for(int i = 0 ; i < nthreads; i ++){
void *ret = NULL;
for (int i = 0 ; i < nthreads; i ++){
if (pthread_join(thid[i], &ret) != 0) {
perror("pthread_create() error");
exit(3);
Expand All @@ -115,29 +135,41 @@ main(void)
}

//Test qv_pthread_scope_split_at
nthreads = 2*n_cores;
nthreads = 2 * ncores;

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%n_cores;
for (int i = 0 ; i < nthreads ; i++) {
colors2[i] = i % ncores;
}

rc = qv_pthread_scope_split_at(mpi_scope, QV_HW_OBJ_CORE, colors2, nthreads, &th_scopes);
rc = qv_pthread_scope_split_at(
mpi_scope, QV_HW_OBJ_CORE, colors2, nthreads, &th_scopes
);
if (rc != QV_SUCCESS) {
ers = "qv_pthread_scope_split_at() failed";
qvi_test_panic("%s (rc=%s)", ers, qv_strerr(rc));
}

thargs_t thargs2[nthreads];
for (int i = 0 ; i < nthreads; i++) {
thargs2[i].scope = th_scopes[i];
thargs2[i].answer = 42;
}

pthread_t thid2[nthreads];
for(int i = 0 ; i < nthreads; i ++){
if (qv_pthread_create(&thid2[i], attr, thread_work, (void *)(th_scopes[i]), th_scopes[i]) != 0) {
perror("pthread_create() error");
exit(1);
const int ptrc = qv_pthread_create(
&thid2[i], attr, thread_work, &thargs2[i], th_scopes[i]
);
if (ptrc != 0) {
ers = "qv_pthread_create() failed";
qvi_test_panic("%s (rc=%s)", ers, strerror(rc));
}
}

for(int i = 0 ; i < nthreads; i ++) {
for (int i = 0 ; i < nthreads; i ++) {
if (pthread_join(thid2[i], &ret) != 0) {
perror("pthread_create() error");
exit(3);
Expand Down
Loading