How to find out in which kernel the process runs in MPI?

I am currently working on a project where I need to know the coreid of the processor on which the process is currently running in MPI? MPI has a function called MPI_Get_processor_name (char * name, int * resultlen) . This gives the name of the node on which the process is running. I want to know the ID of the kernel it is running on? Is it possible? If so, can someone give me a code snippet for this?

thank

0
source share
2 answers

Here is the code that gives coreids for each process on which they are connected. This requires the hwloc library proposed by Christ Iliev in previous comment comments.

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

    int main(int argc, char* argv[])
    {
        int rank, size;
        cpu_set_t mask;
        long num;
        int proc_num(long num);

        hwloc_topology_t topology;
        hwloc_cpuset_t cpuset;
        hwloc_obj_t obj;


        MPI_Init(&argc, &argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &rank);
        MPI_Comm_size(MPI_COMM_WORLD, &size);

        hwloc_topology_init ( &topology);
        hwloc_topology_load ( topology);

        hwloc_bitmap_t set = hwloc_bitmap_alloc();
        hwloc_obj_t pu;
        int err;

        err = hwloc_get_proc_cpubind(topology, getpid(), set, HWLOC_CPUBIND_PROCESS);
        if (err) {
        printf ("Error Cannot find\n"), exit(1);
        }

        pu = hwloc_get_pu_obj_by_os_index(topology, hwloc_bitmap_first(set));
        printf ("Hello World, I am %d and pid: %d coreid:%d\n",rank,getpid(),hwloc_bitmap_first(set));

        int my_coreid = hwloc_bitmap_first(set);
        int all_coreid[size];
        hwloc_bitmap_free(set);
        hwloc_topology_destroy(topology);
        MPI_Finalize();
        return 0;

}
+2

, MPI . MPI . , Open MPI , --bind-to-core --bind-to-socket. , Intel MPI . - MPI MPI_GET_PROCESSOR_NAME node, .

, . , , , , hwloc library ( Open MPI, , , ). - , ( ).

, , . IBM Blue Gene. MPI , MPI_GET_PROCESSOR_NAME .

+1

Source: https://habr.com/ru/post/1585071/


All Articles