當同學要傳送job時,希望大家搭配下列的script來執行。 pbs_parjob.sh

http://sslab.cs.nthu.edu.tw/~dyhong/parallel/faq.html

[ FAQ ]

[1] 每次執行MPI程式時都需要求輸入密碼很多次嗎?
[2] Queue Software使用說明
[3] 使用queue軟體出現 p4_error: Child process exited while making connection to remote process on XXX


[1] Q: 每次執行MPI程式時都需要求輸入密碼很多次嗎?
A: 因為MPI使用SSH protocol登入到各機器上啟動程式執行,因此每次需要登入到其他機器時,系統一定會要求你輸入密碼
如果你已經對每次都要輸入密碼而感到厭煩,透過下列步驟可以讓你以後跑程式時都不需要再輸入密碼
請依序執行下列指令:
# ssh-keygen -t rsa
(接著會要求你輸入一些東西,按<ENTER>即可)
# cd ~/.ssh
# cp id_rsa.pub authorized_keys

[2] Q: Queue Software使用說明
A: 當大家的程式(job)同時在系統中執行時,這些程式間會彼此競爭CPU資源,為了避免同學的程式執行時不會被其他人的程式干擾,
以確保程式的效能數據是準確的,請大家務必使用Queue System。
Queue system會監控整個cluster系統中所有CPUs的狀態,並根據大家送出的程式(並指定此程式執行時需要的CPU個數)、
最後將此程式指派到系統中閒置的CPU(s)上去執行。
以下是幾個大家使用Queue System時常用的指令:
# qsub        (submit a job)
# qstat       (show job status)
# qdel         (cancel a job)

qsub 的使用方法:
當同學要傳送job時,希望大家搭配下列的script來執行。    Download pbs_parjob.sh
執行方式如下:
# qsub pbs_parjob.sh

下列是pbs_parjob.sh的內容:
### Job Name
#PBS -N mpijob
### submits the job to the queue which name is "batch"
###PBS -q batch
#PBS -q batch
### requests 4 nodes, and each node has 2 Processing Units.
#PBS -l nodes=4:ppn=2
### Declare job non-rerunable
#PBS -r n
# Print the name of the node on which this script has started and the time.
echo "====================================================================="
echo "Starting on `hostname` at `date`"
#PBS_NODEFILE=$1
# The environment variable $PBS_NODEFILE lists the name of a file contain
# a list of the nodes that are available to this job.
# The mpirun command will use $PBS_NODEFILE for its machinefile.
# See the mpirun man page for details.
if [ -n "$PBS_NODEFILE" ]; then
if [ -f $PBS_NODEFILE ]; then
# print the nodenames.
echo
echo "Nodes used for this job:"
echo "------------------------"
cat ${PBS_NODEFILE}
echo "------------------------"
# Count the number of lines in $PBS_NODEFILE so that we can get the
# number of available processors. Put this in the $NP variable.
# Unfortunately, PBS doesn't give us this information automatically.
NPROCS=`wc -l < $PBS_NODEFILE`
fi
fi
# Display this job's working directory
echo Working directory is $PBS_O_WORKDIR
cd $PBS_O_WORKDIR
# Use mpirun to run MPI program.
# /opt/mpich/gnu is the MPICH compiled with GCC version, and mpirun is the launch script.
# If your MPI program is compiled with Intel compiler, you can specifies /opt/mpich/intel/bin/mpirun.
# if your MPI program is compiled with PGI compiler, you can specifies /opt/mpich/pgi/bin/mpirun.
###/opt/mpich/bin/mpirun -v -machinefile $PBS_NODEFILE -np $NPROCS ./program/hello3
time mpirun -v -machinefile $PBS_NODEFILE -np $NPROCS ./parallel_program_name
# time ./sequential_program_name
# print end time
echo
echo "Job Ended at `date`"
echo "====================================================================="

Script說明:
PBS -N <Jobname>        (設定Jobname。並在程式結束後產生2個輸出檔,附檔名為.o及.e)
(如上例,Jobname為mpijob,輸出檔為mpijob.o及mpijob.e分別紀錄stdout及stderr的值)
PBS -l nodes=<X>:ppn=<Y>        (設定程式執行需要X nodes,每個node上用Y個processing unit)
(如上例,使用4個nodes,每個node上用2個processing units。)
(當執行sequential程式時,務必設定X=Y=1。若為平行程式,請參照platform中的設定值)
執行MPI程式時,使用time mpirun...那一行。Sequential程式使用time ./sequential...
若欲更動其他的參數值,請詳閱說明文件。

qstat 的使用方法:
# qstat -a        (查詢queue中job的詳細狀態)
# qstat -n        (列出job在各node上執行的詳細情況)

qdel 的使用方法:
# qdel <JobID>        (刪除佇列中id為JobID的程式。JobID可由qstat -a查詢得知)

更多用法請使用man查詢, ex:
# man qsub
# man qstat
# man qdel

[3] Q: 使用queue軟體出現 p4_error: Child process exited while making connection to remote process on XXX
A: 因為queue軟體無法和使用者互動做輸入訊息的動作,所以當需要使用者輸入訊息時,
你的程式會停住不動,直到一段時間後queue軟體將你的程式結束並顯示上述錯誤訊息。
因此有幾點需要注意:
1. 你所寫的程式不要使用到需要和使用者互動的函式,如scanf(), getchar()等。
2. 讓Queue軟體登入到其他機器時不會有互動的清況發生,如輸入密碼或yes/no的問題。測試方法如下執行:
# ssh <Hostname>
     (在Blade server上 Hostname 為node01, node02, ~, node05, node06)
     (在VIA cluster上 Hostname 為VIAC3-01, VIAC3-03, VIAC3-04, ~, VIAC3-11, VIAC3-12)
如果需要輸入密碼,使用FAQ[1]解決。如果需要輸入yes/no則輸入yes。
當確定不會有任何互動的動作發生,則不會出現此錯誤訊息。
原文地址:https://www.cnblogs.com/cy163/p/1192401.html