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

Add a threaded client example #2042

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ examples/legacy
examples/colocate
examples/pset
examples/nodeid
examples/client-threaded

src/sys/powerpc/atomic-32.s
src/sys/powerpc/atomic-64.s
Expand Down
5 changes: 3 additions & 2 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
# Copyright (c) 2013 Mellanox Technologies, Inc. All rights reserved.
# Copyright (c) 2016-2020 Intel, Inc. All rights reserved.
# Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
# Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
Expand Down Expand Up @@ -61,7 +61,8 @@ EXAMPLES = \
legacy \
colocate \
pset \
nodeid
nodeid \
client-threaded

all: $(EXAMPLES)

Expand Down
5 changes: 3 additions & 2 deletions examples/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Copyright (c) 2012 Los Alamos National Security, Inc. All rights reserved.
# Copyright (c) 2013 Mellanox Technologies, Inc. All rights reserved.
# Copyright (c) 2016-2020 Intel, Inc. All rights reserved.
# Copyright (c) 2021-2022 Nanook Consulting. All rights reserved.
# Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
# $COPYRIGHT$
#
# Additional copyrights may follow
Expand Down Expand Up @@ -69,4 +69,5 @@ EXTRA_DIST += \
examples/tool.c \
examples/colocate.c \
examples/pset.c \
examples/nodeid.c
examples/nodeid.c \
examples/client-threaded.c
135 changes: 135 additions & 0 deletions examples/client-threaded.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2011 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2006-2013 Los Alamos National Security, LLC.
* All rights reserved.
* Copyright (c) 2009-2012 Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2011 Oak Ridge National Labs. All rights reserved.
* Copyright (c) 2013-2020 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
* Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/

#define _GNU_SOURCE
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>

#include <pmix.h>

static pmix_proc_t myproc;


void* myThread(void* vargp)
{
pmix_status_t rc;
pmix_proc_t proc;
pmix_value_t *val;

PMIX_LOAD_PROCID(&proc, myproc.nspace, 1);
fprintf(stderr, "Fetching remote\n");
rc = PMIx_Get(&proc, "remote", NULL, 0, &val);
fprintf(stderr, "Client ns %s rank %d: PMIx_Get %s returned: %s(%d)\n",
myproc.nspace, myproc.rank, "foobar", PMIx_Error_string(rc), rc);
return NULL;
}

int main(int argc, char **argv)
{
pmix_status_t rc;
pmix_value_t value;
pmix_value_t *val = &value;
char *tmp;
pmix_proc_t proc;
uint32_t nprocs, n, k;
pmix_info_t *info, i2;
bool flag;
pthread_t thread_id[4];

/* init us - note that the call to "init" includes the return of
* any job-related info provided by the RM. This includes the
* location of all procs in our job */
if (PMIX_SUCCESS != (rc = PMIx_Init(&myproc, NULL, 0))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Init failed: %d\n", myproc.nspace, myproc.rank,
rc);
exit(0);
}
fprintf(stderr, "Client ns %s rank %d Running\n", myproc.nspace, myproc.rank);

value.type = PMIX_UINT64;
value.data.uint64 = 1234;
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_LOCAL, "local", &value))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace,
myproc.rank, rc);
goto done;
}

value.type = PMIX_UINT64;
value.data.uint64 = 5678;
if (PMIX_SUCCESS != (rc = PMIx_Put(PMIX_REMOTE, "remote", &value))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Put internal failed: %d\n", myproc.nspace,
myproc.rank, rc);
goto done;
}

/* push the data to our PMIx server */
if (PMIX_SUCCESS != (rc = PMIx_Commit())) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Commit failed: %d\n", myproc.nspace,
myproc.rank, rc);
goto done;
}

/* call fence to synchronize with our peers - instruct
* the fence operation to collect and return all "put"
* data from our peers */
PMIX_INFO_CREATE(info, 1);
flag = true;
PMIX_INFO_LOAD(info, PMIX_COLLECT_DATA, &flag, PMIX_BOOL);
PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD);
if (PMIX_SUCCESS != (rc = PMIx_Fence(&proc, 1, info, 1))) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Fence failed: %d\n", myproc.nspace, myproc.rank,
rc);
goto done;
}
PMIX_INFO_FREE(info, 1);

// spawn a few threads - each thread attempts to get data
// published by a peer
if (0 == myproc.rank) {
fprintf(stderr, "%u: SPAWNING THREADS\n", myproc.rank);
for (n=0; n < 4; n++) {
pthread_create(&thread_id[n], NULL, myThread, NULL);
}
// collect them all
for (n=0; n < 4; n++) {
pthread_join(thread_id[n], NULL);
}
}

done:
/* finalize us */
rc = PMIx_Finalize(NULL, 0);
if (PMIX_SUCCESS != rc) {
fprintf(stderr, "Client ns %s rank %d:PMIx_Finalize failed: %d\n", myproc.nspace,
myproc.rank, rc);
}
fflush(stderr);
return (0);
}
Loading