- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 Fortran 代码,尽管使用了 omp_set_num_threads()
子程序,我不能设置线程数,即输出说我只使用 1 个线程。我也尝试过 export OMP_NUM_THREADS=4
- 没有结果。
我不知道那段代码有什么问题:
program test
use omp_lib
implicit none
integer :: i, tnr,t
call omp_set_num_threads( 4 )
t = omp_get_num_threads()
write(*,*)'t:',t
!$omp parallel
!$omp do
do i = 1, 20
tnr = omp_get_thread_num()
write( *, * ) 'Thread', tnr, ':', i
end do
!$omp end do
!$omp end parallel
end program test
t: 1
Thread 0 : 1
Thread 0 : 2
Thread 0 : 3
Thread 0 : 4
Thread 0 : 5
Thread 0 : 6
Thread 0 : 7
Thread 0 : 8
Thread 0 : 9
Thread 0 : 10
Thread 0 : 11
Thread 0 : 12
Thread 0 : 13
Thread 0 : 14
Thread 0 : 15
Thread 0 : 16
Thread 0 : 17
Thread 0 : 18
Thread 0 : 19
Thread 0 : 20
openmp
标志激活。 cpu是移动核心i7第二代。
linux-vdso.so.1 (0x00007fff85fce000)
libgfortran.so.3 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/libgfortran.so.3 (0x00007fe310460000)
libm.so.6 => /lib64/libm.so.6 (0x00007fe310169000)
libgomp.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/libgomp.so.1 (0x00007fe30ff5b000)
libgcc_s.so.1 => /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/libgcc_s.so.1 (0x00007fe30fd45000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe30fb28000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe30f77d000)
librt.so.1 => /lib64/librt.so.1 (0x00007fe30f574000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe310749000)
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.4/gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.4/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmp/portage/sys-devel/gcc-4.5.4/work/gcc-4.5.4/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.4 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.4 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.4/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.5.4/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.5.4/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --disable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.5.4/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with- bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.5.4 p1.0, pie-0.4.7'
Thread model: posix
gcc version 4.5.4 (Gentoo 4.5.4 p1.0, pie-0.4.7)
;; Function test (MAIN__)
test ()
{
struct __st_parameter_dt dt_parm.1;
logical(kind=4) D.1545;
struct __st_parameter_dt dt_parm.0;
integer(kind=4) tnr;
integer(kind=4) t;
integer(kind=4) i;
integer(kind=4) i.8;
integer(kind=4) i.7;
integer(kind=4) i.6;
integer(kind=4) tnr.5;
integer(kind=4) i.4;
integer(kind=4) t.3;
<bb 2>:
omp_set_num_threads (&C.1537);
t.3_1 = omp_get_max_threads ();
t = t.3_1;
dt_parm.0.common.filename = &"testmp.f"[1]{lb: 1 sz: 1};
dt_parm.0.common.line = 11;
dt_parm.0.common.flags = 128;
dt_parm.0.common.unit = 6;
_gfortran_st_write (&dt_parm.0);
_gfortran_transfer_character (&dt_parm.0, &"t:"[1]{lb: 1 sz: 1}, 2);
_gfortran_transfer_integer (&dt_parm.0, &t, 4);
_gfortran_st_write_done (&dt_parm.0);
i = 1;
i.4_2 = i;
if (i.4_2 <= 20)
goto <bb 3>;
else
goto <bb 5>;
<bb 3>:
tnr.5_3 = omp_get_thread_num ();
tnr = tnr.5_3;
dt_parm.1.common.filename = &"testmp.f"[1]{lb: 1 sz: 1};
dt_parm.1.common.line = 16;
dt_parm.1.common.flags = 128;
dt_parm.1.common.unit = 6;
_gfortran_st_write (&dt_parm.1);
_gfortran_transfer_character (&dt_parm.1, &"Thread"[1]{lb: 1 sz: 1}, 6);
_gfortran_transfer_integer (&dt_parm.1, &tnr, 4);
_gfortran_transfer_character (&dt_parm.1, &":"[1]{lb: 1 sz: 1}, 1);
_gfortran_transfer_integer (&dt_parm.1, &i, 4);
_gfortran_st_write_done (&dt_parm.1);
i.6_4 = i;
D.1545_5 = i.6_4 == 20;
i.7_6 = i;
i.8_7 = i.7_6 + 1;
i = i.8_7;
if (D.1545_5 != 0)
goto <bb 5>;
else
goto <bb 4>;
<bb 4>:
goto <bb 3>;
<bb 5>:
return;
}
;; Function main (main)
main (integer(kind=4) argc, character(kind=1) * * argv)
{
static integer(kind=4) options.2[8] = {68, 255, 0, 0, 0, 1, 0, 1};
integer(kind=4) D.1552;
<bb 2>:
_gfortran_set_args (argc_1(D), argv_2(D));
_gfortran_set_options (8, &options.2[0]);
test ();
D.1552_3 = 0;
return D.1552_3;
}
最佳答案
设置 OMP_NUM_THREADS
或调用 omp_set_num_threads()
设置 nthreads-var ICV(内部控制变量)。要取回它的值,应该调用 omp_get_max_threads()
而不是 omp_get_num_threads()
.
其次,您的代码中存在数据竞争。默认情况下,OpenMP 会同时处理 tnr
和 t
共享变量 .在这种情况下,tnr
的值由 write
显示语句将是在执行赋值的最后一个线程中获得的值(请注意,当涉及到共享变量时,GCC 会抑制寄存器优化)。
正确的代码如下:
program test
use omp_lib
implicit none
integer :: i, tnr,t
call omp_set_num_threads( 4 )
t = omp_get_max_threads()
write(*,*)'t:',t
!$omp parallel do private(tnr)
do i = 1, 20
tnr = omp_get_thread_num()
write( *, * ) 'Thread', tnr, ':', i
end do
!$omp end parallel do
end program test
请注意,当
do
构造是立即且唯一嵌套在
parallel
中的东西区域,可以使用组合
parallel do
构造并保存两行代码。
.f
中文件,因此被识别为固定源格式。在这种情况下,OpenMP 指令必须遵守以下规则:
The following sentinels are recognized in fixed form source files:
!$omp
|c$omp
|*$omp
Sentinels must start in column 1 and appear as a single word with no intervening characters. Fortran fixed form line length, white space, continuation, and column rules apply to the directive line. Initial directive lines must have a space or zero in column 6, and continuation directive lines must have a character other than a space or a zero in column 6. (emphasis mine)
testmp.f.140t.optimized
的内容中可以明显看出。文件。
关于multithreading - gfortran openmp 无线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19590550/
我正在为一个私有(private)项目编译库,这取决于许多库。具体来说,其中一个依赖项是用 Fortran 编译的。在某些情况下,我看到使用 g77 编译的依赖项,在其他人身上,我看到它是用 gfor
根据 this , gfortran 可以进行整数逻辑转换,但我收到此错误: if (.not.bDropped.and.(zz_unif01() .lt. (1
我听说 g95 不再有效。现在使用哪种编译器是合适的(我将不胜感激提供最新的概述) 最佳答案 截至 2010 年 12 月 29 日,该项目似乎已死。自 2010 年 8 月中旬以来,该项目的博客没有
我有一个针对 ifort 进行了优化的程序,但是我想改用 gfortran 编译它。以下是提供的标志: FCFLAGS= -Vaxlib -CB -mcmodel=large -O -openmp
我正在尝试使用 gfortran 编译器在 Ubuntu 14.04 上使用旧的 CPMD-3.11.1 版本。 在运行 Makefile 时我遇到了这个错误: Error: Unclassifiab
我目前有 Xcode(以及命令行工具)和 gfrotran from HPC安装在我的 Yosemite 系统上,并希望将 HPC 的 gfortran 替换为 Homebrew 的(因为我在使用 H
自升级到优胜美地后,我无法使用 gfortran 进行编译。最初我收到“段错误 11”,然后我: 从 http://hpc.sourceforge.net/ 更新到 gcc v.5.0 重新安装了 X
我做了这个小程序来测试,如果gfortran做尾调用消除: program tailrec implicit none print *, tailrecsum(5, 0) contains recur
我使用的是 ubuntu 12.04,gcc/g++ 4.8,gfortran 是 4.6,我重新安装了 gfortran-4.8 和 gfortran-4.8.dev,仍然没有链接。 当我尝试编译一
有没有办法格式化输出的实数,以便宽度和小数部分都未指定?只需执行以下操作,ifort 就可以做到这一点: write (*, '(F)') num ...但我知道这种用法是特定于编译器的扩展。 Gfo
我需要调试一些 pure用 gfortran 编译的程序中的函数。有什么办法可以忽略 pure声明以便我可以使用 write , print等在这些pure功能不费力? 不幸的是,要删除 pure
是否存在与 C“inline”关键字等效的 Fortran 关键字? 如果存在一些特定于编译器的关键字,gfortran 是否有? 最佳答案 一般来说,Fortran 规范为编译器编写者提供了如何实现
请参阅下面的示例 program test character(10),dimension(5):: models = (/"feddes.swp", "jarvis89.swp", "jarvi
有没有办法强制 gfortran 中的下溢清零? 我不敢相信这是第一次有人问这个问题,但我在任何地方都找不到任何相关内容。如果这是重复的,我很抱歉。 最佳答案 您可以使用支持 Fortran 2003
我在将程序链接到库时遇到问题。我以前从未这样做过,所以我可能做了一些愚蠢的事情,但据我所知,我正在做正确的事情。我需要将程序 foo.f90 链接到库 libbar.a,该库位于我的主目录下其他位置的
使用 gfortran 编译时是否可以使用实数作为迭代器和数组索引?这是一些示例代码: program test real i real testarray(5) testar
我需要一点帮助:根据this site ,最大连续行数有限制。 所以我决定对此进行测试。我编写了一个巨大的 FUNCTION ,它计算在分成 17,146 个连续行的语句中表达的巨大代数公式。 !te
考虑以下代码: subroutine tao_show_this () implicit none type b_struct integer, pointer :: good_user => n
我正在尝试使用 mac-ports (OS-X) 中的 Gfortran 4.7 编译以下简单代码: program main implicit none integer :: n = 1, cloc
我用 Fortran90 编写了一个简单的程序来计算三角形的面积。用户输入三角形的三边,然后程序输出面积。足够简单。 MODULE Triangle_Operations IMPLICIT N
我是一名优秀的程序员,十分优秀!