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 example of child dep termination #2050

Merged
merged 1 commit into from
Oct 18, 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 @@ -135,6 +135,7 @@ examples/colocate
examples/pset
examples/nodeid
examples/client-threaded
examples/dynamic-dep

src/sys/powerpc/atomic-32.s
src/sys/powerpc/atomic-64.s
Expand Down
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ EXAMPLES = \
colocate \
pset \
nodeid \
client-threaded
client-threaded \
dynamic-dep

all: $(EXAMPLES)

Expand Down
3 changes: 2 additions & 1 deletion examples/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ EXTRA_DIST += \
examples/colocate.c \
examples/pset.c \
examples/nodeid.c \
examples/client-threaded.c
examples/client-threaded.c \
examples/dynamic-dep.c
100 changes: 100 additions & 0 deletions examples/dynamic-dep.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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-2019 Intel, Inc. All rights reserved.
* Copyright (c) 2015 Mellanox Technologies, Inc. All rights reserved.
* Copyright (c) 2016 Research Organization for Information Science
* and Technology (RIST). All rights reserved.
* Copyright (c) 2021-2024 Nanook Consulting All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*
*/

#include <stdbool.h>

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <time.h>
#include <unistd.h>

#include "examples.h"
#include <pmix.h>

static pmix_proc_t myproc;

int main(int argc, char **argv)
{
int rc, exitcode;
char nsp2[PMIX_MAX_NSLEN + 1];
pmix_proc_t proc;
pmix_app_t *app;
bool test_dep = true;
pmix_info_t info;

if (1 < argc) {
if (0 == strcmp(argv[1], "dep")) {
test_dep = false;
}
}

/* init us */
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(rc);
}

/* rank=0 calls spawn */
if (0 == myproc.rank) {
PMIX_APP_CREATE(app, 1);
app->cmd = strdup("sleep");
app->maxprocs = 2;
PMIX_ARGV_APPEND(rc, app->argv, app->cmd);
PMIX_ARGV_APPEND(rc, app->argv, "5");

PMIX_INFO_LOAD(&info, PMIX_SPAWN_CHILD_SEP, &test_dep, PMIX_BOOL);
rc = PMIx_Spawn(&info, 1, app, 1, nsp2);
if (PMIX_SUCCESS != rc) {
fprintf(stderr, "Client ns %s rank %d: PMIx_Spawn failed: %s(%d)\n", myproc.nspace,
myproc.rank, PMIx_Error_string(rc), rc);
exitcode = rc;
/* terminate our peers */
PMIX_LOAD_PROCID(&proc, myproc.nspace, PMIX_RANK_WILDCARD);
PMIx_Abort(rc, "FAILED TO START CHILD JOB", &proc, 1);
goto done;
} else {
fprintf(stderr, "Spawn success.\n");
}
PMIX_APP_FREE(app, 1);

// now terminate
}


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

fflush(stderr);
return (0);
}
2 changes: 1 addition & 1 deletion src/docs/show-help-files/help-state-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ its parent:
Parent: %s
Child: %s

This behavior is controlled by setting the PMIX_JOB_CHILD_SEP attribute
This behavior is controlled by setting the PMIX_SPAWN_CHILD_SEP attribute
in the job info provided at time of spawn for the child job. When set to
"true", the runtime will "separate" the child from its parent and allow
it to continue execution after parent termination. Note that this is only
Expand Down
3 changes: 3 additions & 0 deletions src/mca/state/dvm/state_dvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ static void check_complete(int fd, short args, void *cbdata)
PMIX_LIST_FOREACH(jptr, &jdata->children, prte_job_t)
{
if (prte_get_attribute(&jptr->attributes, PRTE_JOB_CHILD_SEP, (void**)&sepptr, PMIX_BOOL) && !sep) {
pmix_output(0, "TERMINATING CHILD");
proc = PMIX_NEW(prte_proc_t);
PMIX_LOAD_PROCID(&proc->name, jptr->nspace, PMIX_RANK_WILDCARD);
pmix_pointer_array_add(&procs, proc);
Expand All @@ -853,6 +854,8 @@ static void check_complete(int fd, short args, void *cbdata)
PMIX_RELEASE(proc);
}
}
} else {
pmix_output(0, "NOT TERMINATING CHILD");
}
PMIX_DESTRUCT(&procs);
}
Expand Down
Loading