Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use the Linux specific <a href="http://man7.org/linux/man-pages/man2/getcpu.2.html" rel="nofollow noreferrer">getcpu(2)</a> syscall (or, as <a href="https://stackoverflow.com/a/19953666/841108">Krishna answered</a>, the Linux specific <a href="http://man7.org/linux/man-pages/man3/sched_getcpu.3.html" rel="nofollow noreferrer">sched_getcpu(3)</a> function wrapping it). Read carefully the man page (that <code>getcpu</code> syscall does not have any libc wrapper!). Notice that it may gives you some obsolete information (because the kernel can -and does- <em>migrate</em> processes or tasks -e.g. threads- at <em>any time</em> from one CPU core to another).</p> <p>Otherwise, your <em>MPI</em> implementation is probably using threads or processes. You could query them with <a href="http://man7.org/linux/man-pages/man2/gettid.2.html" rel="nofollow noreferrer">gettid(2)</a> (which needs some wrapper) for threads, or <a href="http://man7.org/linux/man-pages/man2/getpid.2.html" rel="nofollow noreferrer">getpid(2)</a> for processes.</p> <p>You may want to code:</p> <pre><code>#include &lt;unistd.h&gt; #include &lt;asm/unistd.h&gt; #include &lt;sys/syscall.h&gt; static inline long my_gettid(void) { return syscall(SYS_gettid); } </code></pre> <p>and perhaps something similar for <code>getcpu</code>....</p> <p>You could also use <a href="http://man7.org/linux/man-pages/man5/proc.5.html" rel="nofollow noreferrer">proc(5)</a> e.g. query <code>/proc/self/stat</code> (the 39<sup>th</sup> field gives the <em>processor</em> number)... Perhaps just displaying all of it is the simplest way:</p> <pre><code>{ char line[128]; FILE *fs = fopen("/proc/self/stat","r"); if (!fs) { perror("/proc/self/stat"); exit(EXIT_FAILURE); }; while (!feof(fs)) { memset(line, 0, sizeof(line)); fgets(line, sizeof(line), fs); fputs(line, stdout); }; fclose(fs); } </code></pre> <p>Remember that the Linux kernel (its scheduler) is migrating tasks (i.e. processes or threads) from one CPU core to another one at any time. So querying that is next to useless (the task could have migrated between the moment you query it and the moment you display it).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload