这是定义Fortran程序中线程数的正确方法吗? [英] Is this the proper way to define number of threads in an fortran Program?

查看:606
本文介绍了这是定义Fortran程序中线程数的正确方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为并行计算编写的FORTRAN程序。程序接受参数并且可以将线程的数量定义为参数。示例代码如下:

  COUNT = NARGS()
NTHREADS = 1

! ***获得命令行自变量,如果任何
IF(COUNT.GT.1)然后
! ***变量1
CALL GETARG(1,BUFFER,iStatus)
IF(缓冲区(1:4).EQ .'- NOP'.OR.Buffer(1:4).EQ。' -nop')THEN
PAUSEIT = .FALSE。
ENDIF
IF(Buffer(1:3).EQ .'-NT'.OR.Buffer(1:3).EQ .'- nt')THEN
READ(Buffer( 4:10),*)NTHREADS
ENDIF
IF(COUNT.GT.2)then
! *** ARGUMENT 2
CALL GETARG(2,BUFFER,iStatus)
IF(缓冲区(1:4).EQ .'- NOP'.OR.Buffer(1:4).EQ。' -nop')THEN
PAUSEIT = .FALSE。
ENDIF
IF(Buffer(1:3).EQ .'-NT'.OR.Buffer(1:3).EQ .'- nt')THEN
READ(Buffer( *)NTHREADS
ENDIF
ENDIF
ENDIF



<让我们说我编译的文件名是hellofortran。我可以将线程数定义为

  ./ hellofortran -nt4 

我的程序将用4个线程读取程序。问题是我可以在任何计算机上运行尽可能多的内核。可以说我有双核心处理器。我只有两个核心,但我仍然可以运行6-8个线程或任何数量。我如何正确定义这个特定实例中的线程数?



我希望我解释我的问题。期待尽快听到我如何改进我的计划。谢谢。

Jdbaba

解决方案

如果您使用OpenMP,要设置使用多少个线程,我只需指定环境中的线程数:

  OMP_NUM_THREADS = 4 
./hellofortran

并像通常一样编写OpenMP代码。有线程计数的编程方式,但这对您来说可能更直接。


I have a FORTRAN program written for the parallel computing. The program takes the arguments and the number of threads can be defined as the argument. The sample code is as follows:

COUNT = NARGS()
      NTHREADS = 1

      ! *** GET THE COMMAND LINE ARGUMENTS, IF ANY
      IF(COUNT.GT.1)THEN
        ! *** ARGUMENT 1
        CALL GETARG(1, BUFFER, iStatus)
        IF (Buffer(1:4).EQ.'-NOP'.OR.Buffer(1:4).EQ.'-nop') THEN
          PAUSEIT=.FALSE.
        ENDIF
        IF (Buffer(1:3).EQ.'-NT'.OR.Buffer(1:3).EQ.'-nt') THEN
          READ(Buffer(4:10),*) NTHREADS
        ENDIF
        IF(COUNT.GT.2)THEN
          ! *** ARGUMENT 2
          CALL GETARG(2, BUFFER, iStatus)
          IF (Buffer(1:4).EQ.'-NOP'.OR.Buffer(1:4).EQ.'-nop') THEN
            PAUSEIT=.FALSE.
          ENDIF
          IF (Buffer(1:3).EQ.'-NT'.OR.Buffer(1:3).EQ.'-nt') THEN
            READ(Buffer(4:10),*) NTHREADS
          ENDIF
         ENDIF
      ENDIF

Let's say my compiled file name is "hellofortran". I can define the number of threads as

./hellofortran -nt4 

My program will read the program with 4 threads. The problem is that I can run with as many cores in any computer. Lets say I have dual core processor. I have only two cores but I can still run with 6-8 threads or any number. How can I properly define the number of threads in this particular instance ?

I hope I explained my problem. Looking forward to hearing soon on how can I improve my program. Thanks.

Jdbaba

解决方案

If you're using OpenMP and just looking to set up how many threads to use, I would just specify the number of threads in the environment:

OMP_NUM_THREADS=4
./hellofortran

and write your OpenMP code as you would normally. There are programmatic ways of setting thread counts but this is likely more straightforward for you.

这篇关于这是定义Fortran程序中线程数的正确方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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