Last active
September 30, 2019 16:03
-
-
Save AndiH/f11cfdc45db7f6c4d554a5b3d7eedef4 to your computer and use it in GitHub Desktop.
MPI Rank, OpenMP Thread ID, Core ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
omp_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC = mpicc | |
C_OPT ?= -fopenmp | |
.PHONY: all | |
all: omp_id | |
omp_id: omp_id.c Makefile | |
$(CC) $(C_OPT) -o $@ $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _GNU_SOURCE // sched_getcpu(3) is glibc-specific (see the man page) | |
#include <stdio.h> | |
#include <mpi.h> | |
#include <sched.h> | |
#include <omp.h> | |
int main(int argc, char** argv) { | |
MPI_Init(NULL, NULL); | |
int world_size; | |
MPI_Comm_size(MPI_COMM_WORLD, &world_size); | |
int world_rank; | |
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); | |
#pragma omp parallel | |
{ | |
int thread_num = omp_get_thread_num(); | |
int cpu_num = sched_getcpu(); | |
printf("MPI Rank: %3d, OpenMP Thread ID: %3d, Physical CPU ID: %3d\n", world_rank, thread_num, cpu_num); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment