Paralelize混合f77 f90 Fortran代码? [英] Paralelize mixed f77 f90 Fortran code?

查看:210
本文介绍了Paralelize混合f77 f90 Fortran代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要编写在f77中的代码,但也有用f90语法编写的例程。



我一直在阅读如何在每种情况下使用openMP,但现在我怀疑如果我在相同的代码中使用两种语法,该怎么做? / p>

更具体地说,我应该使用

  use omp_lib 

  include 'omp_lib.h'

但是在同一个.f文件中我有两个sintaxys。如果我同时使用?



我正在用gfortran 4.8.4进行编译。



如果我使用let's say

 请使用omp_lib(表示f90语法)

然后我必须使用通讯员语法

 !$ omp parallel shared(var1,var2)private(i,j)

!$ omp do
do j = 1,n
do i = 1,m
var1(i,j)= var2
end do
end do
!$ omp end do

然而,有几行我会用f77写成一个循环



< pre $ c $ omp parallel shared(w)private(i,j)

c $ omp do
do 20 i = 10,1,-2
write(*,*)'i =',i
20 continue
c $ omp end do

但是这种方式来调用并行循环会被使用omp_lib识别吗?



同样的问题是相反的。首先,您需要使用 use include


解决方案 只有在您调用OpenMP过程时才有效。如果您只有几个!$ omp 指令,则不需要。



您只需要这个,当你可以调用一个过程:

 调用omp_set_num_threads(1)
$ b $或b
$ b $ $ p $ tid = omp_get_thread_num()
code>

,但不适用于指令。



对于Fortran 90及更高版本的代码(即使是固定形式,看起来像Fortran 77)使用

  use omp_lib 

,因为编译器可以更好地检查是否正确调用了函数(它与它们有明确的接口)。

如果代码是真的Fortran 77(而不只是看起来像这样),你必须使用 include ,尽管从技术上讲Fortran 77并不是我知道。这是Fortran 77的通用非标准扩展。


I have a code written mostly in f77 however there are also routines written with the f90 syntax.

I've been reading how to use openMP for each case, but now I have the doubt how should I do it if I have both syntax in the same code?

More specifically should I use

  use omp_lib

or

  include 'omp_lib.h'

but in the same .f file I have both sintaxys. what if I use both?

I am compiling with gfortran 4.8.4.

If I use let's say

use omp_lib (meaning f90 syntax)

Then I have to use the correspondent syntax

!$omp parallel shared ( var1, var2 ) private ( i, j )

!$omp do
do j = 1, n
do i = 1, m
  var1(i,j) = var2
end do
end do
!$omp end do

However a few lines down I'll have a do loop written in f77

 c$omp parallel shared ( w ) private ( i, j )

 c$omp do
  do 20 i = 10, 1, -2
     write(*,*) 'i =', i
  20  continue
 c$omp end do

but this way to call the parallel loop would be recognised by using use omp_lib?

The same question when is the opposite.

解决方案

First, you need the use or include only if you call OpenMP procedures. If you just have a couple of !$omp directives it is not needed.

You only need this, when you call a procedure like:

   call omp_set_num_threads(1)

or

   tid = omp_get_thread_num()

but not for the directives.

For Fortran 90 and later code (even in fixed form which looks like Fortran 77) use

use omp_lib

because the compiler is then better able to check if you call the functions properly (it has an explicit interface to them).

If the code is true Fortran 77 (and not just looking like it), you have to use the include although technically Fortran 77 doesn't even know that. It is a common non-standard extension to Fortran 77.

这篇关于Paralelize混合f77 f90 Fortran代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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