`
deepfuture
  • 浏览: 4336457 次
  • 性别: Icon_minigender_1
  • 来自: 湛江
博客专栏
073ec2a9-85b7-3ebf-a3bb-c6361e6c6f64
SQLite源码剖析
浏览量:79459
1591c4b8-62f1-3d3e-9551-25c77465da96
WIN32汇编语言学习应用...
浏览量:68445
F5390db6-59dd-338f-ba18-4e93943ff06a
神奇的perl
浏览量:101591
Dac44363-8a80-3836-99aa-f7b7780fa6e2
lucene等搜索引擎解析...
浏览量:281388
Ec49a563-4109-3c69-9c83-8f6d068ba113
深入lucene3.5源码...
浏览量:14628
9b99bfc2-19c2-3346-9100-7f8879c731ce
VB.NET并行与分布式编...
浏览量:65648
B1db2af3-06b3-35bb-ac08-59ff2d1324b4
silverlight 5...
浏览量:31356
4a56b548-ab3d-35af-a984-e0781d142c23
算法下午茶系列
浏览量:45255
社区版块
存档分类
最新评论

LINUX-c-pvm(5)-同一台主机

阅读更多

1、主进程 testpvm1,发送字符串,接收大写化的字符串

 

#include "pvm3.h"
#include <stdio.h>


int main(int argc,char *argv[]){
   int RetCode,MessageId;
   int PTid,Tid;
   char Message[100];
   char Result[100];
   printf("testpvm1 get ptid.....\n");   

   PTid=pvm_mytid();//返回调用进程的任务标识符
   if (PTid==PvmSysErr) perror("pvm_mytid() error:PvmSysErr\n");
   printf("spawn testpvm2.....\n");   
//深未来技术 deepfuture.iteye.com
   RetCode=pvm_spawn("testpvm2",NULL,PvmTaskHost,"deepfuture-laptop",1,&Tid);
//启动一个新的PVM子进程testpvm2,用来接收和处理Message消息,转化为大写,Tid为新的任务标识
   if (RetCode==1){
       MessageId=1;//指明当前消息
       strcpy(Message,"deepfuture.iteye.com");
       pvm_initsend(PvmDataDefault);//初始化消息缓冲区
       pvm_pkstr(Message);//对变量Message的内容进行打包    
       pvm_send(Tid,MessageId);//将消息缓冲区的消息发送,MessageId简单指明正在发送的消息
       pvm_recv(Tid,MessageId);//接收消息
       pvm_upkstr(Result);//将消息缓冲区的接收到的内容放到一个数组中。
       printf("send:%s\n",Message);
       printf("recv:%s\n",Result);
       pvm_exit();
       return 0;      
   }
   else{
       printf("不能启动新进程\n");
       pvm_exit();       
       return 1;
   }   
}
 

 

2、从进程 testpvm2,将字符串转化为大写,然后返回给主进程

 

#include "pvm3.h"
#include <stdio.h>

int main(int argc,char *argv[]){
   int RetCode,MessageId;
   int PTid;
   char Message[100];
   char myc[100];
   int i=0;

   printf("testpvm2 get ptid.....\n"); 
 
   PTid=pvm_parent();//返回调用进程的任务标识符
   if (PTid==PvmNoParent) perror("PvmNoParent error\n");
   else if (PTid==PvmSysErr) perror("PvmSysErr error\n");
   
   printf("testpvm2 run.....\n");   

   MessageId=1;//指明当前消息
   pvm_recv(PTid,MessageId);//接收消息 
 //深未来技术 deepfuture.iteye.com
   pvm_upkstr(Message);//对变量Message的内容进行解包 
   while (Message[i]!='\0'){ //将小写转化成大写
              if (islower(Message[i]))   
                  myc[i]=toupper(Message[i]); 
              else 
                  myc[i]=Message[i];    
       i++; 
   } 
   myc[i]='\0';  
   pvm_initsend(PvmDataDefault);//初始化消息缓冲区 
   pvm_pkstr(myc);//对变量Message的内容进行打包
   pvm_send(PTid,MessageId);//将消息缓冲区的消息发送,MessageId简单指明正在发送的消息
   pvm_exit();
   return 0;     

}

 

 3、makefile

 深未来技术 deepfuture.iteye.com

testpvm:testpvm1 testpvm2
	sudo cp /home/deepfuture/private/mytest/pvmtest/testpvm1 /usr/lib/pvm3/bin/LINUX/testpvm1
	sudo cp /home/deepfuture/private/mytest/pvmtest/testpvm2 /usr/lib/pvm3/bin/LINUX/testpvm2 
testpvm1:
	gcc -o /home/deepfuture/private/mytest/pvmtest/testpvm1 -lpvm3 /home/deepfuture/private/mytest/testpvm1.c
testpvm2:
	gcc -o /home/deepfuture/private/mytest/pvmtest/testpvm2 -lpvm3 /home/deepfuture/private/mytest/testpvm2.c
clean:
	rm /home/deepfuture/private/mytest/pvmtest/testpvm*
	sudo rm /usr/lib/pvm3/bin/LINUX/testpvm*

 

 4、二进制文件存放目录 为

   $PVM_ROOT/bin/$PVM_ARCH

   本机为/usr/lib/pvm3/bin/LINUX/

5、启动pvmd

 

pvmd &

6、运行testpvm1

deepfuture@deepfuture-laptop:/usr/lib/pvm3/bin/LINUX$ ./testpvm1

testpvm1 get ptid.....

spawn testpvm2.....

send:deepfuture.iteye.com

recv:DEEPFUTURE.iteye.com

7、在pvm控制台运行testvpm1
deepfuture@deepfuture-laptop:/usr/lib/pvm3/bin/LINUX$ pvm
pvmd already running.
pvm> spawn -> testpvm1
spawn -> testpvm1
[1]
1 successful
t40042
pvm> [1:t40043] testpvm2 get ptid.....
[1:t40043] testpvm2 run.....
[1:t40042] testpvm1 get ptid.....
[1:t40042] spawn testpvm2.....
[1:t40042] send:deepfuture.iteye.com
[1:t40042] recv:DEEPFUTURE.iteye.com
[1:t40042] EOF
[1:t40043] EOF
[1] finished
8、ubuntu使用新立得安装pvm3、libpvm3、pvm-dev

 

 

1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics