random_number()如何并行工作? [英] How does random_number() work in parallel?

查看:63
本文介绍了random_number()如何并行工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

random_number()如何与OpenMP并行工作?

How does random_number() works in parallel with OpenMP?

如果我在没有并行化的情况下运行程序,我总是会得到相同的结果,但是在并行化的情况下,每次都会得到不同(但相似)的结果.

If I run my program without parallelization I always get the same result, but with parallelization I get different (but similar) results every time.

推荐答案

通常不保证有关random_number的线程安全或线程性能. Fortran标准根本不了解OpenMP.

There is no guarantee about thread safety or threading performance about random_number in general. The Fortran standard does not know OpenMP at all.

各个编译器可能会为您提供一些保证,但是它们仅对特定编译器中存在的版本有效.例如,当前的gfortran版本提供了线程安全的随机数生成器,并提供了多线程程序(例如使用OpenMP指令),每个线程将具有其自己的随机数状态." 其他编译器可能有所不同.值得注意的是,您的用户可能要使用的编译器可能会有所不同,您可能对此一无所知.

Individual compilers may offer you some guarantees, but they will be only valid for the version present in the particular compiler. For example, the current gfortran version supplies a thread-safe random number generator and "Note that in a multi-threaded program (e.g. using OpenMP directives), each thread will have its own random number state." Other compilers may differ. Notably, the compiler your user may want to use may differ and you may not know about that.

有专用的并行随机数生成器.例如,我使用的库的修改版本使用Gib Bogle并行处理了针对几种随机数分布的Ziggurat方法,我添加了xoroshiro128 +的实现作为基础算法,类似于Gfortran所使用的算法.还有其他类似算法的实现方式,标准C ++包含一些实际上定义为使用特定算法的新生成器,因此您可以调用它们.

There are dedicated parallel random number generators available. For example, I use a modified version of the library that uses the Ziggurat method for several random number distributions, was parallelized by Gib Bogle and I added the implementation of xoroshiro128+ as the underlying algorithm, similar to the one used by Gfortran. There are other implementations of similar algorithms available and standard C++ contains some new generators which are actually defined to use a specific algorithm, so you could call them.

这篇关于random_number()如何并行工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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