cs205-lecture-examples

Example codes used during Harvard CS205 lectures
git clone https://git.0xfab.ch/cs205-lecture-examples.git
Log | Files | Refs | README | LICENSE

helper.h (656B)


      1 #ifndef HELPER_H_T9QL1OGR
      2 #define HELPER_H_T9QL1OGR
      3 
      4 #include <string>
      5 #include <unistd.h>
      6 
      7 // return cpu and numa node id
      8 // https://stackoverflow.com/questions/16862620/numa-get-current-node-core
      9 unsigned long tacc_rdtscp(int *core, int *node)
     10 {
     11     unsigned long a,d,c;
     12     __asm__ volatile("rdtscp" : "=a" (a), "=d" (d), "=c" (c));
     13     *node= (c & 0xFFF000)>>12;
     14     *core = c & 0xFFF;
     15     return ((unsigned long)a) | (((unsigned long)d) << 32);;
     16 }
     17 
     18 // get hostname of node
     19 std::string gethostname(void)
     20 {
     21     std::string hostname(1024, '\0');
     22     gethostname(&hostname.front(), hostname.size());
     23     return hostname;
     24 }
     25 
     26 #endif /* HELPER_H_T9QL1OGR */