1. 程式人生 > >Linux平臺下搭建Fortran並行編譯環境(SLES10 )

Linux平臺下搭建Fortran並行編譯環境(SLES10 )

SLES10 Linux(kernel-2.6.16.21-0.8)平臺下搭建Fortran並行編譯環境
一.Fortran編譯器的安裝
Linux安裝盤一般都自帶有Fortran編譯器,在SuSe9.1以前均帶有g77,在Suse9.2以後為gfortran。但是,相對來說,由於g77和gfortran的編譯的程式執行效率不是很高,所以都會選擇再安裝專業的Fortran編譯器。
主流的Fortran 90/95編譯器有PGI Fortran、HP Fortran Compiler(由Fortran PowerStation進化過來的)和Intel Fortran Compiler等。因為Intel Fortran Compiler9.1是Intel提供的免費的Non-Commercial版本,且在Intel平臺上,具有較高的編譯效率。它的發行版有Windows和Linux兩種。在此,主要介紹在SLES10.0 上安裝 Intel Fortran Compiler 9.1 的過程。
1.下載安裝包
本次安裝包從ftp上下載,ifcliv91.bin,為光碟檔案,可以直接拷貝到目錄/home/hou/software/intel_fc_91下。
2.解壓安裝檔案,命令如下:
編譯器是安裝在/opt/intel目錄下,協議則在該目錄下的licenses資料夾中。最後還要指定licenses的位置。具體命令如下:
#mkdir -p /opt/intel/licenses
#cp /home/hou/isoftware/intel_fc_91/Crack/i*.lic /opt/intel/licenses
# export INTEL_LICENSE_FILE=opt/intel/licenses
3.安裝程式,命令如下:
#cd /home/hou/isoftware/intel_fc_91
#./install.sh
按照安裝提示,逐步安裝即可。一般情況下,可以順利安裝完畢,在此安裝包中一共包含有以下編譯器,可以全部安裝,也可以選擇安裝其中之一。
Intel® Fortran Compiler for IA-32 Based Applications
? Intel® Fortran Compiler for Linux for IA-32 applications, version 9.1
? Intel® Debugger for IA-32 applications, version 9.1  
Intel® Fortran Compiler for Intel EM64T-Based Applications
? Intel® Fortran Compiler for Linux for Intel EM64T-Based applications, version 9.1
? Intel® Debugger for Intel EM64T-based applications, version 9.1  
Intel® Fortran Compiler for Itanium-Based Applications
? Intel® Fortran compiler for Itanium-based applications, version 9.1
? Intel® Debugger for Itanium-based applications, version 9.1
? Intel® Itanium Assembler to produce Itanium-based applications, version 9.0  
安裝Intel Fortran Compiler for Intel EM64T-Base,預設目錄就是/opt/intel/fce/9.1.032/。安裝編譯器完成之後,繼續可以安裝Linux Application Debugger for Intel EM64T-base applications,它預設安裝在/opt/intel/idbe/9.1.023/下。最後選擇“x”退出安裝程式。
4.安裝完成,將編譯器路徑加入到環境變數中。命令如下:
server:~ # vi .bash_profile
export PATH=$PATH:/opt/intel/fce/9.1.032/bin
export MANPATH=$MANPATH:/opt/intel/fce/9.1.032/man
server:~ # source .bash_profile
   在執行編譯以後執行中,會出現找不到連結庫檔案的問題,這是由於沒有將Intel編譯器的庫檔案新增到連結庫搜尋中,編輯/etc/ ld.so.conf,新增intel庫檔案的路徑。具體如下:
server:~ # vi /etc/ld.so.conf
/usr/X11R6/lib64
/usr/X11R6/lib/Xaw3d
/usr/X11R6/lib
/usr/x86_64-suse-linux/lib
/usr/local/lib
/opt/kde3/lib
/opt/gnome/lib
/lib64
/lib
/usr/lib64
/usr/lib
/usr/local/lib64
/opt/kde3/lib64
/opt/gnome/lib64
/opt/intel/fce/9.1.032/lib
include /etc/ld.so.conf.d/*.conf
然後執行命令生效。
server:/etc # ldconfig -v
安裝完畢,可以編寫小程式進行測試。
2. PICH的安裝
1.下載並安裝 mpich包(用hou使用者)
下載mpi的linux安裝包:mpich-1.2.7p1.tar。放到/home/hou/software 目錄下。解壓檔案: tar xvf mpich-1.2.7p1.tar.然後在/home/hou目錄下建立安裝目錄。
server /etc> cd /home/hou
server /home/hou> mkdir mpich
回到解壓縮得到的目錄,設定環境變數,指定用ifort編譯器進行安裝。命令:
server /home/hou> cd /home/hou/software/mpich-1.2.7p1/
server software/mpich-1.2.7p1> setenv FC ifort
server software/mpich-1.2.7p1> setenv F90 ifort
server software/mpich-1.2.7p1> ./configure -with-flibname=mpich-ifort -prefix=/home/hou/mpich
其中/home/hou/mpich為所指定安裝的目錄。然後make對MPI進行編譯。
server software/mpich-1.2.7p1>make
測試安裝是否正確,到example/basic目錄下進行測試。
server software/mpich-1.2.7p1>cd example/basic
server software/mpich-1.2.7p1>make cpi
server software/mpich-1.2.7p1>../../bin/mpirun -np 4 cpi
至此,MPI還沒有開始正式的安裝,只是預安裝。若執行成功,即可進行最後的安裝。最後,將mpich安裝到指定的目錄
server software/mpich-1.2.7p1>make install
2.安裝後文件配置
在所有的機器的/etc/hosts.equiv檔案內新增啟動MPI程式的機器名。如:
#
# hosts.equiv   This file describes the names of the hosts which are
#               to be considered "equivalent", i.e. which are to be
#               trusted enough for allowing rsh(1) commands.
#
# hostname
server
bingxing70
bingxing71
bingxing72
bingxing73
bingxing74
bingxing75
… …
或者在帳戶目錄下建立 .rhosts檔案:
在hou目錄下建立指令碼檔案 .cshrc新增環境變數,並生效。
server /home/hou> vi .cshrc
setenv MANPATH ${MANPATH}:/opt/intel/fce/9.1.032/man
setenv PATH ${PATH}:/home/hou/mpich/bin
setenv MANPATH ${MANPATH}:/home/hou/mpich/mansource .cshrc
server /home/hou> source .cshrc
最後還要到無盤機器上建立指令碼檔案 .cshrc
至此,SLES建立了MPI訊息傳遞形式的,Intel Fortran編譯器下的並行Fortran編譯和執行環境。
關於編譯優化引數的,參見附錄文章:英特爾多核平臺程式設計優化大賽報告