Open MPI logo

Hardware Locality Users' Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Users mailing list

Subject: [hwloc-users] Problem getting cpuset of MPI task
From: Hendryk Bockelmann (bockelmann_at_[hidden])
Date: 2011-02-09 10:53:24

Since I am new to hwloc there might be a misunderstanding from my side,
but I have a problem getting the cpuset of MPI tasks. I just want to run
a simple MPI program to see on which cores (or CPUs in case of
hyperthreading or SMT) the tasks run, so that I can arrange my MPI

For the program below I get the following output:

Process 0 of 2 on tide
Process 1 of 2 on tide
--> cpuset of process 0 is 0x0000000f
--> cpuset of process 0 after singlify is 0x00000001
--> cpuset of process 1 is 0x0000000f
--> cpuset of process 1 after singlify is 0x00000001

So why do both MPI tasks report the same cpuset?
Here is the program (attached you find the output of

#include <stdio.h>
#include <string.h>
#include "hwloc.h"
#include "mpi.h"

int main(int argc, char* argv[]) {

    hwloc_topology_t topology;
    hwloc_bitmap_t cpuset;
    char *str = NULL;
    int myid, numprocs, namelen;
    char procname[MPI_MAX_PROCESSOR_NAME];


    printf("Process %d of %d on %s\n", myid, numprocs, procname);


    /* get native cpuset of this process */
    cpuset = hwloc_bitmap_alloc();
    hwloc_get_cpubind(topology, cpuset, 0);
    hwloc_bitmap_asprintf(&str, cpuset);
    printf("--> cpuset of process %d is %s\n", myid, str);
    hwloc_bitmap_asprintf(&str, cpuset);
    printf("--> cpuset of process %d after singlify is %s\n", myid, str);


    return 0;