Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <time.h>
- #include <string.h>
- #include <stdlib.h>
- #include "pvm3.h"
- void rodzic()
- {
- int dlugosc;
- char* tekst= "To jest ja test lab pvm rtgba";
- printf("Tekst: %s\n", tekst);
- dlugosc= strlen(tekst);
- struct pvmhostinfo *hostp;
- int result, check, i, ilhost, ilarch, tid, tidmaster;
- char bufor[64];
- //gethostname(bufor, 20);
- //printf("Rodzic: %s\n", bufor); //nazwa rodzica
- if(tidmaster=pvm_mytid() <0) {
- pvm_perror("enroll");
- exit(1);
- }
- pvm_config(&ilhost, &ilarch, &hostp);
- printf(tekst);
- tid = (int*) calloc (ilhost, sizeof(int));
- for(i=0; i<ilhost; i++)
- {
- if(i>=dlugosc)
- break;
- check=pvm_spawn("/home/pvm/pvm3/lab/example", 0, PvmTaskHost, hostp[i].hi_name, 1, &tid);
- pvm_initsend(PvmDataDefault);
- pvm_pkbyte((tekst+i), 1, 1);
- pvm_send(tid[i],100);
- if(!check)
- printf("Błąd powołania potomka do życia na %s\n", hostp[i].hi_name);
- }
- result=0;
- int liczba =0;
- int count;
- while(result<ilhost)
- {
- pvm_recv(-1, 200);
- pvm_upkint(&count, 1, 1);
- if(count==1)
- liczba++;
- result++;
- }
- pvm_exit();
- printf("Liczba znaków 'a': ", liczba);
- }
- void potomek()
- {
- char buf;
- int m;
- int charcount;
- while(1)
- {
- pvm_recv(-1, 100);
- pvm_upkbyte(&buf, 1, 1);
- if(buf == 'a') {
- charcount=1;
- }
- int ptid=pvm_parent();
- pvm_initsend(PvmDataDefault);
- pvm_pkint(&charcount, 1, 1);
- pvm_send(ptid, 200);
- }
- }
- main()
- {
- if(pvm_parent() == PvmNoParent)
- rodzic();
- else
- potomek();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement