Loading Makefile 0 → 100644 +13 −0 Original line number Diff line number Diff line COMP = cc FLAGS = -fopenmp hello_mpi_omp: hello_mpi_omp.o ${COMP} ${FLAGS} hello_mpi_omp.o -o hello_mpi_omp hello_mpi_omp.o: hello_mpi_omp.c ${COMP} ${FLAGS} -c hello_mpi_omp.c PHONY: clean clean: rm -f hello_mpi_omp *.o hello_mpi_omp.c 0 → 100644 +40 −0 Original line number Diff line number Diff line /* ------------------------------------------------------------- MPI + OpenMP Hello, World program to help understand process and thread mapping to physical CPU cores and hardware threads ------------------------------------------------------------- */ #define _GNU_SOURCE #include <stdio.h> #include <mpi.h> #include <sched.h> #include <omp.h> int main(int argc, char *argv[]){ MPI_Init(&argc, &argv); int size; MPI_Comm_size(MPI_COMM_WORLD, &size); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); char name[MPI_MAX_PROCESSOR_NAME]; int resultlength; MPI_Get_processor_name(name, &resultlength); int hwthread; int thread_id = 0; #pragma omp parallel default(shared) private(hwthread, thread_id) { thread_id = omp_get_thread_num(); hwthread = sched_getcpu(); printf("MPI %03d - OMP %03d - HWT %03d - Node %s\n", rank, thread_id, hwthread, name); } MPI_Finalize(); return 0; } Loading
Makefile 0 → 100644 +13 −0 Original line number Diff line number Diff line COMP = cc FLAGS = -fopenmp hello_mpi_omp: hello_mpi_omp.o ${COMP} ${FLAGS} hello_mpi_omp.o -o hello_mpi_omp hello_mpi_omp.o: hello_mpi_omp.c ${COMP} ${FLAGS} -c hello_mpi_omp.c PHONY: clean clean: rm -f hello_mpi_omp *.o
hello_mpi_omp.c 0 → 100644 +40 −0 Original line number Diff line number Diff line /* ------------------------------------------------------------- MPI + OpenMP Hello, World program to help understand process and thread mapping to physical CPU cores and hardware threads ------------------------------------------------------------- */ #define _GNU_SOURCE #include <stdio.h> #include <mpi.h> #include <sched.h> #include <omp.h> int main(int argc, char *argv[]){ MPI_Init(&argc, &argv); int size; MPI_Comm_size(MPI_COMM_WORLD, &size); int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); char name[MPI_MAX_PROCESSOR_NAME]; int resultlength; MPI_Get_processor_name(name, &resultlength); int hwthread; int thread_id = 0; #pragma omp parallel default(shared) private(hwthread, thread_id) { thread_id = omp_get_thread_num(); hwthread = sched_getcpu(); printf("MPI %03d - OMP %03d - HWT %03d - Node %s\n", rank, thread_id, hwthread, name); } MPI_Finalize(); return 0; }