可以命名OpenMP Worker-threads吗?

发布于 2025-02-09 07:49:46 字数 1364 浏览 2 评论 0原文

使用TOP,我可以看到我的应用程序工作 - 并按照预期消耗多个CPU。但是,我希望能够通过不同的工人深入到CPU消费中,但是,这些在Top的输出中是难以置信的,它显示了所有这些名称:myProgram {myProgram {myProgram} < /代码>。

是否有OpenMP子句允许每个工人命名?如果没有,也许其他一些技巧 - 使用pthread_setname_np()也许 - 哪些将在所有(或大多数)平台上使用?

update :我尝试使用pthread_setname_np()和AM观察意外结果:多个带有同名的线程...我的程序使用嵌套并行化:

  1. ###的Pragma OMP Parallel正在调用一个函数来上传文件 - 多个此类上传并行运行。
  2. 上传 - 功能循环在给定文件上,一次读取一个块。然后,每个块是:
  • 馈送到sha256_update()
  • fed to sftp_write()

该想法是计算每个文件的摘要,而该文件无论如何都通过RAM。摘要更新和写作是并行完成的:

#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(), ""));
    }
}

我在顶部和GDB中看到的奇怪的是几个名为“ SFTP 1”的线程。 有时 一个名称“ sha 1”闪烁,但从来没有其他数字,即使我看到7个文件并行上传...

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:

  1. The #pragma omp parallel for is calling a function to upload a file -- multiple such uploads are running in parallel.
  2. 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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

古镇旧梦 2025-02-16 07:49:46

没有标准方法可以在OpenMP中设置线程名称(假设我正确读取了规范)。您可以在规范中检查: https”> https:> https: //www.openmp.org/wp-content/uploads/openmp-api-specification-5-2.pdf

如果您的OpenMP运行时使用PTHREAD(通常在Linux和BSD上,但肯定在Windows上),则可以使用函数pthread_sers在并行部分中获取线程上下文。然后,您可以使用函数pthread_setname_np。但是,请不要说该功能的论点会更改所使用的操作系统。请参阅如何在中设置线程名称linux pthreads?。简而言之,没有便携式解决方案。

There is no standard way to set a thread name in OpenMP (assuming I read the specification correctly). You can check that in the specification: https://www.openmp.org/wp-content/uploads/OpenMP-API-Specification-5-2.pdf .

If your OpenMP runtime use pthread (typically on Linux and BSD but certainly not on Windows), then you can use the function pthread_self to get the thread context in a parallel section. Then you can use the function pthread_setname_np. However, please not that the argument of the function change regarding the OS used. See How to set the name of a thread in Linux pthreads? . Put it shortly, there is no portable solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文