各位高手,我初学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;
}
}
|
|