最近写水动力的程序,体系太大,必须用并行才能算的动,无奈只好找了并行编程的资料学习了。我想我没有必要在博客里开一个什么并行编程的教程之类,因为网上到处都是,我就随手记点重要的笔记吧。这里主要是openmp的~
1 临界与归约
在涉及到openmp的并行时,最需要注意的就是被并行的区域中的公共变量,对于需要reduce的变量,尤其要注意,比如这段代码:
program main
implicit none
include 'omp_lib.h'
integer N,M,i
real(kind=8) t
N=20000
t=0.0
!$OMP PARALLEL DO
do i=1,N
t=t+float(i);
M=OMP_get_num_threads()
enddo
write(*, "('t = ', F20.5, ' running on ', I3, ' threads.')") t,M
pause
stop
end
<