title: Can OpenMP worker-threads be named?
body: <p>Using <code>top</code>, I can see my application working -- and consuming multiple CPUs, as expected. However, I'd like to be able to drill down into the CPU-consumption by the different workers, and yet, these are indiscernible in top's output, which shows the same name for all of them: <code>myprogram{myprogram}</code>.</p>
  <p>Is there an OpenMP clause allowing to name each worker? If not, perhaps some other tricks -- using the <code>pthread_setname_np()</code>, perhaps -- which will work on all (or most) platforms?</p>
  <p><em>Update</em>: I tried using the <code>pthread_setname_np()</code> and am observing unexpected results: multiple threads running with the same name... My program uses nested parallelization:</p>
  <ol>
  <li>The <code>#pragma omp parallel for</code> is calling a function to upload a file -- multiple such uploads are running in parallel.</li>
  <li>The <code>upload</code>-function loops over the given file, reading a block at a time. Each block is then:</li>
  </ol>
  <ul>
  <li>fed to <code>SHA256_Update()</code></li>
  <li>fed to <code>sftp_write()</code></li>
  </ul>
  <p>The idea is to compute each file's digest, while the file is passing through the RAM anyway. The digest-update and the writing are done in parallel:</p>
  <pre><code>#pragma omp parallel sections
  {
  #pragma omp section
      {
          char tname[32];
          sprintf(tname, sizeof tname, &quot;SHA %d&quot;, omp_get_thread_num());
          pthread_setname_np(pthread_self(), tname));
          SHA256_Update(&amp;ctx, buf);
          pthread_setname_np(pthread_self(), &quot;&quot;));
      }
  #pragma omp section
      {
          char tname[32];
          sprintf(tname, sizeof tname, &quot;SFTP %d&quot;, omp_get_thread_num());
          pthread_setname_np(pthread_self(), tname));
          written = sftp_write(sftp, buf, bufsize);
          pthread_setname_np(pthread_self(), &quot;&quot;));
      }
  }
  </code></pre>
  <p>Bizarrely, what I see in top -- and in gdb -- are several threads named &quot;SFTP 1&quot;. <em>Sometimes</em> a name &quot;SHA 1&quot; flashes by, but never any other number, even though I see 7 files being uploaded in parallel...</p>