URN Logo
UNIX Resources » Linux » China Linux Forum » C/C++编程版 » 20 » PVM 例子 希望高手帮忙运行一下
announcement 声明: 本页内容为中国Linux论坛的内容镜像,文章的版权以及其他所有的相关权利属于中国Linux论坛和相应文章的作者,如果转载,请注明文章来源及相关版权信息。
Resources
China Linux Forum(finished)
Linux Forum(finished)
FreeBSD China(finished)
linuxforum.net
  业界新闻与评论
  自由软件杂谈
  IT 人生
  Linux软件快递
  翻译作坊
  Linux图书与评论
  GNU Emacs/XEmacs
  Linux 中文环境和中文化
  Linux桌面与办公软件
  Linux 多媒体与娱乐版
  自由之窗Mozilla
  笔记本电脑上的Linux
  Gentoo
  Debian 一族
  网络管理技术
  Linux 安装与入门
  WEB服务器和FTP服务器
  域名服务器和邮件服务器
  Linux防火墙和代理服务器应用
  文件及打印服务器
  技术培训与认证
  Linux内核技术
  Linux 嵌入技术
  Linux设备驱动程序
  Linux 集群技术
  LINUX平台数据库
  系统和网络安全
  CPU 与 编译器
  系统计算研究所专栏
  Linux下的GUI软件开发
  C/C++编程版
  PHP 技 术
  Java&jsp技术
  Shell编程技术
  Perl 编 程
  Python 编 程
  XML/Web Service 技术
  永远的Unix
  FreeBSD世界
   
PVM 例子 希望高手帮忙运行一下
Author: alianhuang    Posted: 2006-01-17 06:25    Length: 4,601 byte(s)
[Original] [Print] [Top]
各位高手,我初学PVM, 现在编了一个程序,一个MASTER, 把几个不同的英语单词让SLAVER帮他做一个
颠倒,也就是,如果是How, SLAVER会把它变为woH,然后传回给MASTER, 程序我已经编好的,但我的PVM
设置有点问题,编译SLAVER 的时候不行,哪位大侠帮忙看看,谢谢,这个星期内,再谢谢.
MASTER文件叫hello.c
SLAVER叫hello_other.c

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

struct word_structure {
char name[20];

};
typedef struct word_structure turn;

int main (int argc, char* argv[]) {
work turn[4]={{"How",0},{"now",0},{"brown",0},{"cow?",0};
int i,j;
char rename;
/* PVM info */
int my_tid, tids[32];
int nhost, narch, num_spawned;
struct pvmhostinfo *hostp;

/* Buffer information */
char buf[32];
int bufnum, msgtype;

/* Start PVM stuff */

/* Get my task id */
my_tid = pvm_mytid();
pvm_catchout(stdout);
/* Get virtual machine configuration */
pvm_config(&nhost, &narch, &hostp);

/* Start up child processes */
num_spawned = pvm_spawn("hello_other", 0, PvmTaskDefault, "", 4, tids);
printf("%d spawned. ", num_spawned);
if (num_spawned != 4) {
fprintf(stderr, "Wrong number of spawned Hello_other ");
exit(1);
}

/* Send the words to the branches */
for (i=0; i<num_spawned; i++) {
/* initialize the buffers */
pvm_initsend(PvmDataDefault);
/* pack the index */
pvm_pkint(&i, 1, 1);
/* pack the word */
pvm_pkstr(turn[i].name, 4, 1);
/* Send off the info */
pvm_send(tids[i], 5);
printf("Sent %s to %d ", turn[i].name, tids[i]);
}

printf(" Words Results: ");

/* Get the words */
for(i=0; i<num_spawned; i++) {
pvm_recv(-1, 4);
pvm_upkint(&j, 1, 1);
pvm_upkstr(&rename, 1, 1);
printf("%s(%d) = %2.2f ", branch[j].name, j, rename);
}
}


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

int main (int argc, char *argv[]) {
/* Initialize some variables */
char buf[100];
int my_tid;
int parent_id, bufid, my_index;
char rename;
my_tid=pvm_mytid();
/* Get the task id of the parent process */
parent_id = pvm_parent();
printf(" in slave %d ",my_tid);
/* Recieve from the parent */
bufid = pvm_recv(parent_id, 5);
/* Unpack the index of the student we're calculating */
pvm_upkint(&my_index, 1, 1);
/* Unpack the words */
pvm_upstr(name,4, 1);

/* Where the real work is done */
rename = TurnChar(name);

/* Initialize the send buffer */
pvm_initsend(PvmDataDefault);
/* Pack the index of the student */
pvm_pkint(&my_index, 1, 1);
/* Pack the words */
pvm_pkstr(&rename, 1, 1);
/* Send it on its merry way... */
pvm_send(parent_id, 4);

/* Quit PVM */
pvm_exit();
exit(0);
}

void TurnChar(char* pszCharInput)
{
if(pszCharInput==NULL)
{
return;
}

int iLength = strlen(pszCharInput);
if(iLength==0 || iLength==1)
{
return;
}

char szTemp;
int iMod = iLength%2-1;
int iCount = iLength/2;
iLength = iCount;
while(iCount>0)
{
szTemp = pszCharInput[iLength-iCount];
pszCharInput[iLength-iCount] = pszCharInput[iLength+iCount+iMod];
pszCharInput[iLength+iCount+iMod] = szTemp;

--iCount;
}
}

[Original] [Print] [Top]
« Previous thread
请教linux下写大于2G文件问题。
C/C++编程版
20
Next thread »
autoscan autoconf
     

Copyright © 2007 UNIX Resources Network, All Rights Reserved.      About URN | Privacy & Legal | Help | Contact us
备案序号: 京ICP备05006143    webmaster: webmaster@unixresources.net
This page created on 2008-07-17 03:52:22, cost 0.041677951812744 ms.