Fortran 77多线程C ++应用程序中的公共块 [英] Fortran 77 common blocks in multithreading C++ application

查看:237
本文介绍了Fortran 77多线程C ++应用程序中的公共块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个调用Fortran 77例程的C ++程序。主要的C ++程序可能运行多线程。然而,发生Fortran 77例程隐藏几个公共块,每个调用取决于其参数修改。



恐怕所有公共块可以共享

第一个问题:Am

对不对?


  • 第二个问题:有没有简单的方法来避免它?重写Fortran例程似乎不可负担,我宁愿寻找一种方式,使每个线程都有自己的所有公共块的副本(不大,应该快速复制)。我不知道编译选项是否会帮助,或者如果OpenMP可以帮助我。



  • 解决方案

    是,共享块是共享的。



    在OpenMP中,可以指定一个公共块为THREADPRIVATE。每个线程动态创建公共块的新实例。要从原始数据复制数据,请使用COPYIN说明符。另请参见 OpenMP threadprivate和private之间的区别



    基本语法是

     !$ OMP THREADPRIVATE(/ cb /,...)

    其中cb是公共块的名称。请参见 https://computing.llnl.gov/tutorials/openMP/#THREADPRIVATE


    I develop one C++ program which calls a Fortran 77 routine. The main C++ program may run multithreaded. However, it happens that the Fortran 77 routine hides several common blocks which are modified on each call depending on its arguments.

    I am afraid that all common blocks may be shared between multiple threads and that concurrent accesses to these blocks will probably mess everything.

    • First question : Am I right? Would common blocks be shared between multiple threads?

    • Second question : Is there a simple way to avoid it? Rewriting the Fortran routines seems unaffordable, I am rather looking for a way so that each thread has its own copy of all common blocks (which are not large, should be fast to copy). I do not know if a compiling option would help or if OpenMP could help me.

    解决方案

    Yes, common blocks are shared.

    In OpenMP it is possible to specify a common block as THREADPRIVATE. Each thread than makes a new instance of the common block dynamically. To copy the data from the original one use the COPYIN specifier. See also Difference between OpenMP threadprivate and private

    The basic syntax is

    !$OMP THREADPRIVATE (/cb/, ...)  
    

    where cb is the name of a common block. See https://computing.llnl.gov/tutorials/openMP/#THREADPRIVATE

    这篇关于Fortran 77多线程C ++应用程序中的公共块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆