Linux上編譯計算Palabos案例指南

Linux上編譯計算Palabos

Palabos用戶文檔

原始文檔

The most recent version of Palabos can be downloaded at the address www.palabos.org. It is now shown how to compile and run the software under Linux or other Unix-like environment. The library is exempt from external dependencies: all you need is a working compiler environment, including a modern C++ compiler (for example the free GCC compiler), the command make, and a reasonably recent version of the Python interpreter. To get started, download the tarball of the most recent version of Palabos, for example plb-v1.1r0.tgz, and move it to the directory in which you wish the code to reside (we will refer to this directory under the name of $(PALABOS)). In the following, the code is staying at this location, as there is currently no explicit installation process. Instead, compiled libraries are deposited in the directory $(PALABOS)/lib/. Unpack the code, using for example the command tar xvfz plb-v1.1r0.tgz.
The library Palabos makes use of an on-demand compilation process. The code is compiled the first time it is used by an end-user application, and then automatically re-used in future, until a new compilation is needed due to a modification of the code or compilation options. To see how this works, change into the directory of one of the example programs, such as $(PALABOS)/examples/showCases/cylinder2D/. Type make to compile both the Palabos library and the example program under standard conditions with the GCC compiler, and execute the program with the command ./cavity2D. The program simulates the 2D flow around a cylinder; if the software ImageMagick is installed on your system, the program saves GIF images in the tmp/ subdirectory, representing the velocity field at selected time steps.
To use a different compiler, compile for parallel execution, or modify other compilation options, edit the file Makefile in the local directory. The following options are particularly often modified:
debug Turn on this flag to compile in debug mode. The resulting executable is a bit slower but easier to analyze in search for bugs. The recommended default behavior is to turn on debug mode.
MPIparallel Turn on this flag to compile for parallel execution.
serialCXX Specify the compiler to use for serial programs.
parallelCXX Specify the compiler to use for parallel programs.
optimFlags Specify the compiler options to use when the flag optimize is true.
compileFlags Specify additional compiler options, which are for example specific to your hardware environment. Typical options are -DPLB_BGP or -DPLB_MAC_OS_X when compiling on a BlueGene or on a Mac respectively.
If MPI is installed on your system (and if you have several cores or processors available), you can try to compile the code in parallel and execute it, say with two threads, through a command of the type mpirun -np 2 ./cavity2d. Note that the execution time of the example program is dominated by output operations. To observe a significant speed improvement in the parallel program, the output operations need first to be commented in the source code.

文檔翻譯

最新版本的Palabos可以通過網址www.palabos.org下載。現在演示如何在Linux或其他類unix環境下編譯和運行軟件。該庫不受外部依賴:您所需要的只是一個工作的編譯器環境,包括一個現代的c++編譯器(例如免費的GCC編譯器)、make命令和一個相當新的Python解釋器。首先,下載Palabos的最新版本的壓縮包,例如plb-v1.1r0。並將其移動到您希望代碼駐留的目錄(我們將以$(PALABOS)的名稱引用此目錄)。在下面的代碼中,代碼將保留在這個位置,因爲目前沒有顯式的安裝過程。相反,編譯後的庫存儲在$(PALABOS)/lib/目錄中。使用命令tar xvfz plb-v1.1r0.tgz解壓縮代碼。
庫Palabos使用按需編譯過程。代碼在最終用戶應用程序第一次使用時進行編譯,然後在將來自動重新使用,直到由於修改代碼或編譯選項而需要重新編譯爲止。要查看這是如何工作的,請切換到其中一個示例程序的目錄,如$(PALABOS)/examples/showCases/cylinder2d /。使用GCC編譯器在標準條件下編譯Palabos庫和示例程序,並使用命令./cavity2D執行程序。該程序模擬了圓柱周圍的二維流動;如果您的系統上安裝了ImageMagick軟件,該程序將GIF圖像保存在tmp/子目錄中,表示所選時間步長的速度字段。
若要使用不同的編譯器、爲並行執行進行編譯或修改其他編譯選項,請在本地目錄中編輯文件Makefile。特別經常修改下列選擇:
debug 在調試模式下打開此標誌以進行編譯。生成的可執行文件稍微慢一些,但是更容易分析,以查找bug。推薦的默認行爲是打開調試模式。
MPIparallel 打開這個標誌來編譯並行執行。
serialCXX 指定用於串行程序的編譯器。
parallelCXX 指定用於並行程序的編譯器。
optimFlags 指定標記優化爲真時使用的編譯器選項。
compileFlags 指定額外的編譯器選項,例如,這些選項特定於您的硬件環境。在BlueGene或Mac上編譯時,典型的選項是-DPLB_BGP或-DPLB_MAC_OS_X。
如果MPI安裝在您的系統上(如果您有多個可用的內核或處理器),那麼您可以嘗試並行地編譯代碼,並通過mpirun -np 2 ./cavity2d類型的命令執行它,比如使用兩個線程。注意,示例程序的執行時間由輸出操作決定。要觀察並行程序中顯著的速度改進,首先需要在源代碼中註釋輸出操作。

解釋說明

makefile文件修改:

# Name of source files in current directory to compile and link with Palabos
projectFiles = cavity2d.cpp

一般只需要改這一條,Makefile文件大致相同,這條是修改編譯所需源代碼文件的名稱,你寫好的程序放在examples/showcases/下新建的文件夾中,其他的都不需要改,只需要改這個文件名,按照你自己的程序文件名來寫,使用make,即可以編譯成可執行文件,再使用 ./文件名 運行文件。
如果沒有辦法編譯,請查看是否安裝了gcc,沒有辦法使用mpi,請自行編譯安裝openmpi

發佈了9 篇原創文章 · 獲贊 1 · 訪問量 2669
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章