Skip to content

Commit 380cc8f

Browse files
author
Ralph Castain
committed
Add a test program to help diagnose binding issues
1 parent 2992d6d commit 380cc8f

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

orte/test/mpi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PROGS = mpi_no_op mpi_barrier hello hello_nodename abort multi_abort simple_spawn concurrent_spawn spawn_multiple mpi_spin delayed_abort loop_spawn loop_child bad_exit pubsub hello_barrier segv accept connect hello_output hello_show_help crisscross read_write ziatest slave reduce-hang ziaprobe ziatest bcast_loop parallel_w8 parallel_w64 parallel_r8 parallel_r64 sio sendrecv_blaster early_abort debugger singleton_client_server intercomm_create spawn_tree init-exit77 mpi_info info_spawn server client paccept pconnect ring hello.sapp
1+
PROGS = mpi_no_op mpi_barrier hello hello_nodename abort multi_abort simple_spawn concurrent_spawn spawn_multiple mpi_spin delayed_abort loop_spawn loop_child bad_exit pubsub hello_barrier segv accept connect hello_output hello_show_help crisscross read_write ziatest slave reduce-hang ziaprobe ziatest bcast_loop parallel_w8 parallel_w64 parallel_r8 parallel_r64 sio sendrecv_blaster early_abort debugger singleton_client_server intercomm_create spawn_tree init-exit77 mpi_info info_spawn server client paccept pconnect ring hello.sapp binding
22

33
all: $(PROGS)
44

orte/test/mpi/binding.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* -*- C -*-
2+
*
3+
* $HEADER$
4+
*
5+
* The most basic of MPI applications
6+
*/
7+
8+
#define _GNU_SOURCE
9+
#include <stdio.h>
10+
#include <sys/types.h>
11+
#include <unistd.h>
12+
#include <sched.h>
13+
#include "opal/mca/hwloc/hwloc.h"
14+
#include "mpi.h"
15+
16+
#include "orte/util/proc_info.h"
17+
18+
int main(int argc, char* argv[])
19+
{
20+
int rank, size, rc;
21+
hwloc_cpuset_t cpus;
22+
char *bindings;
23+
cpu_set_t *mask;
24+
int nrcpus, c;
25+
size_t csize;
26+
char hostname[1024];
27+
28+
MPI_Init(&argc, &argv);
29+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30+
MPI_Comm_size(MPI_COMM_WORLD, &size);
31+
32+
gethostname(hostname, 1024);
33+
cpus = hwloc_bitmap_alloc();
34+
rc = hwloc_get_cpubind(opal_hwloc_topology, cpus, HWLOC_CPUBIND_PROCESS);
35+
hwloc_bitmap_list_asprintf(&bindings, cpus);
36+
37+
printf("[%s;%d] Hello, World, I am %d of %d [%d local peers]: get_cpubind: %d bitmap %s\n",
38+
hostname, (int)getpid(), rank, size, orte_process_info.num_local_peers, rc,
39+
(NULL == bindings) ? "NULL" : bindings);
40+
41+
nrcpus = sysconf(_SC_NPROCESSORS_ONLN);
42+
mask = CPU_ALLOC(nrcpus);
43+
csize = CPU_ALLOC_SIZE(nrcpus);
44+
CPU_ZERO_S(csize, mask);
45+
if ( sched_getaffinity(0, csize, mask) == -1 ) {
46+
CPU_FREE(mask);
47+
perror("sched_getaffinity");
48+
return -1;
49+
}
50+
51+
for ( c = 0; c < nrcpus; c++ ) {
52+
if ( CPU_ISSET_S(c, csize, mask) ) {
53+
printf("[%s:%d] CPU %d is set\n", hostname, (int)getpid(), c);
54+
}
55+
}
56+
57+
CPU_FREE(mask);
58+
59+
MPI_Finalize();
60+
return 0;
61+
}

0 commit comments

Comments
 (0)