Using top
, 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: myprogram{myprogram}
.
Is there an OpenMP clause allowing to name each worker? If not, perhaps some other tricks -- using the pthread_setname_np()
, perhaps -- which will work on all (or most) platforms?
Update: I tried using the pthread_setname_np()
and am observing unexpected results: multiple threads running with the same name... My program uses nested parallelization:
- The
#pragma omp parallel for
is calling a function to upload a file -- multiple such uploads are running in parallel. - The
upload
-function loops over the given file, reading a block at a time. Each block is then:
- fed to
SHA256_Update()
- fed to
sftp_write()
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:
#pragma omp parallel sections
{
#pragma omp section
{
char tname[32];
sprintf(tname, sizeof tname, "SHA %d", omp_get_thread_num());
pthread_setname_np(pthread_self(), tname));
SHA256_Update(&ctx, buf);
pthread_setname_np(pthread_self(), ""));
}
#pragma omp section
{
char tname[32];
sprintf(tname, sizeof tname, "SFTP %d", omp_get_thread_num());
pthread_setname_np(pthread_self(), tname));
written = sftp_write(sftp, buf, bufsize);
pthread_setname_np(pthread_self(), ""));
}
}
Bizarrely, what I see in top -- and in gdb -- are several threads named "SFTP 1". Sometimes a name "SHA 1" flashes by, but never any other number, even though I see 7 files being uploaded in parallel...