#define _GNU_SOURCE #include #include "mpi.h" #include #include #include #include #include #include int main (int argc, char *argv[]) { int i, procs, count, rank, namelength; char host[MPI_MAX_PROCESSOR_NAME]; cpu_set_t mask; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&count); printf("Running with %d (size of comm_world)\n",count); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Get_processor_name(host, &namelength); sched_getaffinity(0, sizeof(mask), &mask); procs = sysconf(_SC_NPROCESSORS_ONLN); count = CPU_COUNT(&mask); printf("Affinity Procs %d und count %d\n",procs,count); if (procs != count) { char cores[1024]; cores[0] = '\0'; char buffer[10]; buffer[0] = '\0'; count=0; for (i=0; i 0) strncat(cores, ",", sizeof(buffer)); strncat(cores, buffer, sizeof(buffer)); count++; } } printf("MPI rank %2d is running on %s and uses %d of %d cores (%s)\n", rank, host, count, procs, cores); } else printf("MPI rank %2d is running on %s and uses all %d cores\n", rank, host, procs); sleep(180); MPI_Finalize(); return 0; }