[mpich] MPICH primary repository branch, master, updated. v3.2a1-43-g818b6a6
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "MPICH primary repository". The branch, master has been updated via 818b6a61a2f4653dc12da9c14c46ab866ba2a02b (commit) from e4fb945f8c0ebff106d3c5758420c9311274e148 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://git.mpich.org/mpich.git/commitdiff/818b6a61a2f4653dc12da9c14c46ab866b... commit 818b6a61a2f4653dc12da9c14c46ab866ba2a02b Author: halim amer <[email protected]> Date: Fri Sep 5 14:43:31 2014 -0500 Added an example for checking on which CPU a process is running on. This example does not rely on getcpu() or sched_getcpu() which are not available on old kernels/glibc. Signed-off-by: Ken Raffenetti <[email protected]> diff --git a/src/pm/hydra/examples/print_process_bind.c b/src/pm/hydra/examples/print_process_bind.c new file mode 100644 index 0000000..7bc37e6 --- /dev/null +++ b/src/pm/hydra/examples/print_process_bind.c @@ -0,0 +1,66 @@ +/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */ +/* + * + * (C) 2014 by Argonne National Laboratory. + * See COPYRIGHT in top-level directory. + */ +#define PATH_MAX 100 + +#include "mpi.h" +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <string.h> + +/* This example can be used to check on which node+CPU + * each process is running on. This can serve to confirm + * The correctness of a Process-CPU binding policy for instance. + * + * To get the CPU Id on which a process is running, + * one can use the getcpu() or sched_getcpu(). + * However, getcpu() is only supported by Linux kernels + * >= 2.6.19 for x86_64 and i386 architectures. Also, + * sched_getcpu() is only available since glibc 2.6. + * + * This example implements an alternative, for systems + * not satisfying these requirements, by checking the column + * 39 of /proc/$pid/stat. + * + */ + +int main(int argc, char **argv) +{ + int rank, size, namelen; + FILE *fp; + char path[PATH_MAX]; + char processor_name[MPI_MAX_PROCESSOR_NAME]; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + MPI_Get_processor_name(processor_name, &namelen); + + char shell_cmd[100]; + sprintf(shell_cmd, "cat /proc/%d/stat | awk '{print $39}'", getpid()); + + if (rank == 0) { + printf("----------------------\n"); + printf(" PROCESS/CPU BINDING\n"); + printf("----------------------\n"); + } + + fp = popen(shell_cmd, "r"); + + while (fgets(path, PATH_MAX, fp) != NULL) { + printf("%s[%d]: running on CPU %s", processor_name, rank, path); + } + + pclose(fp); + + fflush(stdout); + + + MPI_Finalize(); + + return 0; +} ----------------------------------------------------------------------- Summary of changes: src/pm/hydra/examples/print_process_bind.c | 66 ++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-) create mode 100644 src/pm/hydra/examples/print_process_bind.c hooks/post-receive -- MPICH primary repository
participants (1)
-
noreply@mpich.org