intel visual fortran 在visual studio中如何正常的使用openmp并行程序.docx
- 文档编号:23013069
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:14
- 大小:98.57KB
intel visual fortran 在visual studio中如何正常的使用openmp并行程序.docx
《intel visual fortran 在visual studio中如何正常的使用openmp并行程序.docx》由会员分享,可在线阅读,更多相关《intel visual fortran 在visual studio中如何正常的使用openmp并行程序.docx(14页珍藏版)》请在冰豆网上搜索。
intelvisualfortran在visualstudio中如何正常的使用openmp并行程序
在vs中利用ivf进行openmp的程序设计
一:
设置成openmp的可使用配置
我的配置是IVF11.1,vstudio2008,Openmp3,进入代码界面后要设置属性,---fortran--language--process--OpenMpDirctives为Generateparallelcode如图所示:
这个并行的问题,我研究了很长时间,首先你要明确以下几点才能并行:
1你的计算机是双核以上的
2计算机的系统是64位的如XP64位(原因是现在的CPU多是采用64位架构,因此系统也要是64位的0,当然23位的也是可以的。
关键是确定你的cpu和对应的ivf
3你所用的IVF有64位组件,也异是在安装时会有64MT。
。
。
(在安装的过程中可以看到这个组件的安装)
4在IVF中要配置参数,project--(×)properties/fortran/language/process/openMPDirectives——generateparallelcode(Qopenmp)
5你的程序可以并行,即程序中有可以并行的地方,前后没有逻辑关系
基本上把这几点弄懂了,差不多可以进行简单的并行计算了
programmain
!
*****************************************************************************80
!
!
!
MAINisthemainprogramforTEST_OMP.
!
!
Discussion:
!
!
TEST_OMPestimatesthevalueofPI.
!
!
ThisprogramusesOpenMPparallelizationdirectives.
!
!
Itshouldrunproperlywhetherparallelizationisusedornot.
!
!
However,theparallelversioncomputesthesuminadifferent
!
orderthantheserialversion;someofthequantitiesaddedare
!
quitesmall,andsothiswillaffecttheaccuracyoftheresults.
!
!
Modified:
!
!
29January2003
!
!
Author:
!
!
JohnBurkardt
!
!
AFORTRAN90modulemaybeavailable:
!
!
useomp_lib
!
!
AFORTRAN77includefilemaybeavailable:
!
!
include'omp_lib.h'
!
implicitnone
integer,parameter:
:
r4_logn_max=9
integerid
integernthreads
integeromp_get_num_procs
integeromp_get_num_threads
integeromp_get_thread_num
calltimestamp()
write(*,'(a)')''
write(*,'(a)')'TEST_OMP'
write(*,'(a)')'FORTRAN90version'
write(*,'(a)')''
write(*,'(a)')'EstimatethevalueofPIbysummingaseries.'
write(*,'(a)')''
write(*,'(a)')'ThisprogramincludesOpenMPdirectives,which'
write(*,'(a)')'maybeusedtoruntheprograminparallel.'
write(*,'(a)')''
write(*,'(a)')'Thenumberofprocessorsavailable:
'
write(*,'(a,i8)')'OMP_GET_NUM_PROCS()=',omp_get_num_procs()
nthreads=4
write(*,'(a)')''
write(*,'(a,i8,a)')'CallOMP_SET_NUM_THREADS,andrequest',&
nthreads,'threads.'
callomp_set_num_threads(nthreads)
!
!
NotethatthecalltoOMP_GET_NUM_THREADSwillalwaysreturn1
!
ifcalledoutsideaparallelregion!
!
!
$OMPparallelprivate(id)
id=omp_get_thread_num()
write(*,'(a,i3)')'Thisisprocess',id
if(id==0)then
write(*,'(a)')''
write(*,'(a)')'CallingOMP_GET_NUM_THREADSinsidea'
write(*,'(a)')'parallelregion,wegetthenumberof'
write(*,'(a,i3)')'threadsis',omp_get_num_threads()
write(*,'(a)')''
endif
!
$OMPendparallel
callr4_test(r4_logn_max)
write(*,'(a)')''
write(*,'(a)')'TEST_OMP'
write(*,'(a)')'Normalendofexecution.'
write(*,'(a)')''
calltimestamp()
stop
end
subroutiner4_test(logn_max)
!
*****************************************************************************80
!
!
!
R4_TESTestimatesthevalueofPIusingsingleprecision.
!
!
Discussion:
!
!
PIisestimatedusingNterms.Nisincreasedfrom10^2to10^LOGN_MAX.
!
ThecalculationisrepeatedusingbothsequentialandOpenMPenabledcode.
!
WallclocktimeismeasuredbycallingSYSTEM_CLOCK.
!
!
Modified:
!
!
06January2003
!
!
Author:
!
!
JohnBurkardt
!
implicitnone
integerclock_max
integerclock_rate
integerclock_start
integerclock_stop
realerror
realestimate
integerlogn
integerlogn_max
character(len=3)mode
integern
realr4_pi
realtime
write(*,'(a)')''
write(*,'(a)')'R4_TEST:
'
write(*,'(a)')'EstimatethevalueofPI,'
write(*,'(a)')'usingsingleprecisionarithmetic.'
write(*,'(a)')''
write(*,'(a)')'N=numberoftermscomputedandadded;'
write(*,'(a)')''
write(*,'(a)')'ESTIMATE=thecomputedestimateofPI;'
write(*,'(a)')''
write(*,'(a)')'ERROR=(thecomputedestimate-PI);'
write(*,'(a)')''
write(*,'(a)')'TIME=elapsedwallclocktime;'
write(*,'(a)')''
write(*,'(a)')'Notethatyoucan''tincreaseNforever,because:
'
write(*,'(a)')'A)ROUNDOFFstartstobeaproblem,and'
write(*,'(a)')'B)maximumintegersizeisaproblem.'
write(*,'(a)')''
write(*,'(a,i12)')'Themaximuminteger:
',huge(n)
write(*,'(a)')''
write(*,'(a)')''
write(*,'(a)')'NModeEstimateErrorTime'
write(*,'(a)')''
n=1
dologn=2,logn_max
mode='OMP'
callsystem_clock(clock_start,clock_rate,clock_max)
callr4_pi_est_omp(n,estimate)
callsystem_clock(clock_stop,clock_rate,clock_max)
time=real(clock_stop-clock_start)/real(clock_rate)
error=abs(estimate-r4_pi())
write(*,'(i12,2x,a3,2x,f14.10,2x,g14.6,2x,g14.6)')&
n,mode,estimate,error,time
n=n*10
enddo
return
end
subroutiner4_pi_est_omp(n,estimate)
!
*****************************************************************************80
!
!
!
R4_PI_EST_OMPestimatesthevalueofPI,usingOpenMP.
!
!
Discussion:
!
!
Thecalculationisbasedontheformulafortheindefiniteintegral:
!
!
Integral1/(1+X**2)dx=Arctan(X)
!
!
Hence,thedefiniteintegral
!
!
Integral(0<=X<=1)1/(1+X**2)dx
!
=Arctan
(1)-Arctan(0)
!
=PI/4.
!
!
Astandardwaytoapproximateanintegralusesthemidpointrule.
!
IfwecreateNequallyspacedintervalsofwidth1/N,thenthe
!
midpointoftheI-thintervalis
!
!
X(I)=(2*I-1)/(2*N).
!
!
Theapproximationfortheintegralisthen:
!
!
Sum(1<=I<=N)(1/N)*1/(1+X(I)**2)
!
!
InordertocomputePI,wemultiplythisby4;wealsocanpullout
!
thefactorof1/N,sothattheformulayouseeintheprogramlookslike:
!
!
(4/N)*Sum(1<=I<=N)1/(1+X(I)**2)
!
!
Untilroundoffbecomesanissue,greateraccuracycanbeachievedby
!
increasingthevalueofN.
!
!
Modified:
!
!
06January2003
!
!
Author:
!
!
JohnBurkardt
!
!
Parameters:
!
!
Input,integerN,thenumberoftermstoaddup.
!
!
Output,realESTIMATE,theestimatedvalueofpi.
!
implicitnone
realh
realestimate
integeri
integern
realsum2
realx
h=1.0E+00/real(2*n)
sum2=0.0E+00
!
!
$OMPparalleldoprivate(x)shared(h)reduction(+:
sum2)
!
doi=1,n
x=h*real(2*i-1)
sum2=sum2+1.0E+00/(1.0E+00+x**2)
enddo
estimate=4.0E+00*sum2/real(n)
return
end
functionr4_pi()
!
*****************************************************************************80
!
!
!
R4_PIreturnsthevalueofpi.
!
!
Modified:
!
!
02February2000
!
!
Author:
!
!
JohnBurkardt
!
!
Parameters:
!
!
Output,realR4_PI,thevalueofpi.
!
implicitnone
realr4_pi
r4_pi=3.14159265358979323846264338327950288419716939937510E+00
return
end
subroutinetimestamp()
!
*****************************************************************************80
!
!
!
TIMESTAMPprintsthecurrentYMDHMSdateasatimestamp.
!
!
Example:
!
!
May3120019:
45:
54.872AM
!
!
Modified:
!
!
31May2001
!
!
Author:
!
!
JohnBurkardt
!
!
Parameters:
!
!
None
!
implicitnone
character(len=8)ampm
integerd
character(len=8)date
integerh
integerm
integermm
character(len=9),parameter,dimension(12):
:
month=(/&
'January','February','March','April',&
'May','June','July','August',&
'September','October','November','December'/)
integern
integers
character(len=10)time
integervalues(8)
integery
character(len=5)zone
calldate_and_time(date,time,zone,values)
y=values
(1)
m=values
(2)
d=values(3)
h=values(5)
n=values(6)
s=values(7)
mm=values(8)
if(h<12)then
ampm='AM'
elseif(h==12)then
if(n==0.and.s==0)then
ampm='Noon'
else
ampm='PM'
endif
else
h=h-12
if(h<12)then
ampm='PM'
elseif(h==12)then
if(n==0.and.s==0)then
ampm='Midnight'
else
ampm='AM'
endif
endif
endif
write(*,'(a,1x,i2,1x,i4,2x,i2,a1,i2.2,a1,i2.2,a1,i3.3,1x,a)')&
trim(month(m)),d,y,h,':
',n,':
',s,'.',mm,trim(ampm)
return
end
!
=====================================
COPY上面的程序,可以完全运行成功,运行界面如下:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- intel visual fortran 在visual studio中如何正常的使用openmp并行程序 studio 如何 正常 使用 openmp 并行 程序
链接地址:https://www.bdocx.com/doc/23013069.html