PVM (Parallel Virtual Machine) 是用於網絡並行計算的軟體工具,將異構計算機網絡連接起來,如同一組分散式並行處理器。支援 C/Fortran,提供通訊原語實現任務間訊息傳遞、同步、動態緩衝區管理、進程組等功能,具備容錯、易安裝配置、免費開源等特點。
/etc/environment)PVM_ROOT=/usr/lib/pvm3
PVM_ARCH=LINUX
$PVM_ROOT/hostfile)deepfuture-laptop
&deepfuture-javaeye
&deepfuture-lx lo=deepfuture
ep=/home/deepfuture/private/mytest/pvmtest/
& 前綴:不自動加入該主機lo=:指定非登入 PVM 環境的使用者名稱ep=:二進制程式目錄.rhosts 信任名單deepfuture-laptop
pvmd hostfile & # 或直接 pvmd &
$HOME/pvm3/bin/
pvm
pvm> quit
$ testpro
# 或在 pvm 控制台
pvm> spawn -> testpro
/etc/hosts 設定hostname1 10.30.13.58
hostname2 10.30.13.62
PVM_ROOT=/usr/share/pvm3
PVM_ARCH=LINUX
export PVM_ROOT PVM_ARCH
.rhosts 互信pvm01 pvmgroup
pvm02 pvmgroup
pvm> add pvm01
1 successful
HOST DTID
pvm01 80000
pvm> halt
testpvm1.c#include "pvm3.h"
#include
int main() {
int RetCode, MessageId = 1;
int PTid, Tid;
char Message[100], Result[100];
PTid = pvm_mytid();
RetCode = pvm_spawn("testpvm2", NULL, PvmTaskHost, "deepfuture-laptop", 1, &Tid);
if (RetCode == 1) {
strcpy(Message, "deepfuture.iteye.com");
pvm_initsend(PvmDataDefault);
pvm_pkstr(Message);
pvm_send(Tid, MessageId);
pvm_recv(Tid, MessageId);
pvm_upkstr(Result);
printf("send:%s\nrecv:%s\n", Message, Result);
pvm_exit();
return 0;
} else {
printf("無法啟動子進程\n");
pvm_exit();
return 1;
}
}
testpvm2.c#include "pvm3.h"
#include
#include
int main() {
int MessageId = 1;
int PTid = pvm_parent();
char Message[100], myc[100];
int i = 0;
pvm_recv(PTid, MessageId);
pvm_upkstr(Message);
while (Message[i] != '\0') {
myc[i] = islower(Message[i]) ? toupper(Message[i]) : Message[i];
i++;
}
myc[i] = '\0';
pvm_initsend(PvmDataDefault);
pvm_pkstr(myc);
pvm_send(PTid, MessageId);
pvm_exit();
return 0;
}
Makefiletestpvm: testpvm1 testpvm2
sudo cp testpvm1 /usr/lib/pvm3/bin/LINUX/
sudo cp testpvm2 /usr/lib/pvm3/bin/LINUX/
testpvm1: gcc -o testpvm1 -lpvm3 testpvm1.c
testpvm2: gcc -o testpvm2 -lpvm3 testpvm2.c
clean:
rm testpvm*
sudo rm /usr/lib/pvm3/bin/LINUX/testpvm*
./testpvm1
testpvm1 get ptid.....
spawn testpvm2.....
send:deepfuture.iteye.com
recv:DEEPFUTURE.iteye.com
PVM 控制台執行同樣成功,展示跨進程訊息傳遞與資料處理流程。