[araim1@maya-usr1 ~]$ cat /proc/cpuinfo processor : 0 vendor_id : GenuineIntel cpu family : 6 model : 62 model name : Intel(R) Xeon(R) CPU E5-2650 v2 @ 2.60GHz stepping : 4 cpu MHz : 2599.948 cache size : 20480 KB physical id : 0 siblings : 8 core id : 0 cpu cores : 8 apicid : 0 initial apicid : 0 fpu : yes fpu_exception : yes cpuid level : 13 wp : yes flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms bogomips : 5199.89 clflush size : 64 cache_alignment : 64 address sizes : 46 bits physical, 48 bits virtual power management: ... 15 other cores are displayed in the same format ... [araim1@maya-usr1 ~]$
[araim1@maya-usr1 ~]$ cat /proc/self/stat 48982 (cat) R 9744 48982 9744 34818 48982 8192 185 0 0 0 0 0 0 0 20 0 1 0 137436614 103354368 134 18446744073709551615 4194304 4235780 140737488346592 140737488343784 252896458544 0 0 0 0 0 0 0 17 2 0 0 0 0 0 [araim1@maya-usr1 ~]$
[araim1@maya-usr1 ~]$ CPU_ID=$(cat /proc/self/stat) [araim1@maya-usr1 ~]$ echo $CPU_ID | gawk '{print $39}' 2 [araim1@maya-usr1 ~]$
#include "getcpuid.h" #include <stdlib.h> #include <stdio.h> #include <string.h> /* * This code is adapted from an example at: * http://brokestream.com/procstat.html */ int get_cpu_id() { /* Get the the current process' stat file from the proc filesystem */ FILE* procfile = fopen("/proc/self/stat", "r"); long to_read = 8192; char buffer[to_read]; int read = fread(buffer, sizeof(char), to_read, procfile); fclose(procfile); // Field with index 38 (zero-based counting) is the one we want char* line = strtok(buffer, " "); for (int i = 1; i < 38; i++) { line = strtok(NULL, " "); } line = strtok(NULL, " "); int cpu_id = atoi(line); return cpu_id; }
#ifndef GETCPUID_H #define GETCPUID_H int get_cpu_id(); #endif
#include <mpi.h> #include <stdio.h> #include "getcpuid.h" int main(int argc, char** argv) { int id, np; char processor_name[MPI_MAX_PROCESSOR_NAME]; int processor_name_len; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Get_processor_name(processor_name, &processor_name_len); int cpu_id = get_cpu_id(); printf("Hello from process %03d out of %03d, hostname %s, cpu_id %d\n", id, np, processor_name, cpu_id); MPI_Finalize(); return 0; }
PROGNAME := get_cpu main: getcpuid.h mpicc -std=c99 main.c getcpuid.c -o $(PROGNAME) clean: rm -f $(PROGNAME) *.o
#!/bin/bash #SBATCH --job-name=getcpu_parallel #SBATCH --output=slurm.out #SBATCH --error=slurm.err #SBATCH --partition=batch #SBATCH --nodes=2 #SBATCH --ntasks-per-node=8 #SBATCH --constraint=hpcf2013 srun ./get_cpu
[araim1@maya-usr1 get-cpu-id]$ make mpicc -std=c99 main.c getcpuid.c -o get_cpu [araim1@maya-usr1 get-cpu-id]$ sbatch run.slurm Submitted batch job 9216 [araim1@maya-usr1 get-cpu-id]$ cat slurm.out Hello from process 001 out of 016, hostname n68, cpu_id 2 Hello from process 002 out of 016, hostname n68, cpu_id 4 Hello from process 003 out of 016, hostname n68, cpu_id 6 Hello from process 004 out of 016, hostname n68, cpu_id 8 Hello from process 005 out of 016, hostname n68, cpu_id 10 Hello from process 006 out of 016, hostname n68, cpu_id 12 Hello from process 000 out of 016, hostname n68, cpu_id 0 Hello from process 009 out of 016, hostname n69, cpu_id 2 Hello from process 010 out of 016, hostname n69, cpu_id 4 Hello from process 011 out of 016, hostname n69, cpu_id 6 Hello from process 012 out of 016, hostname n69, cpu_id 8 Hello from process 007 out of 016, hostname n68, cpu_id 14 Hello from process 008 out of 016, hostname n69, cpu_id 0 Hello from process 013 out of 016, hostname n69, cpu_id 10 Hello from process 014 out of 016, hostname n69, cpu_id 12 Hello from process 015 out of 016, hostname n69, cpu_id 14 [araim1@maya-usr1 get-cpu-id]$