Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "pvm3.h"
- #include <stdlib.h>
- #define NAMELEN 3
- // Jakub Plachta, Marcel Janotta
- void parentProgram();
- void childProgram();
- main (int argc , char** argv)
- {
- printf("test\n");
- if (pvm_parent() == PvmNoParent)
- parentProgram();
- else
- childProgram();
- }
- //Liczba wystapien litery 'a' w pliku
- void parentProgram()
- {
- int i, counter;
- int tidmaster, *tid, ilhost, ilarch;
- struct pvmhostinfo *info;
- FILE *handle = fopen("data.txt", "r");
- char chr;
- size_t len = 0;
- ssize_t read;
- counter = 0;
- /* zgłoszenie procesu do systemu PVM */
- tidmaster = pvm_mytid();
- /* sprawdzenie konfiguracji maszyny wirtualnej */
- pvm_config (&ilhost, &ilarch, &info);
- /* przygotowanie tablicy identyfikatorów zadań */
- tid = (int*) calloc (ilhost, sizeof(int));
- for (i = 0; i < 1; i++) {
- pvm_spawn("/home/pvm/pvm3/lab9/plik", NULL, PvmTaskHost, info[i].hi_name, 1, &tid[i]);
- /* wyślij komunikat synchronizacyjny do procesu potomka */
- pvm_initsend (PvmDataDefault);
- chr = fgetc(handle);
- printf("%d \n", chr);
- pvm_pkbyte(&chr, 1, 1);
- pvm_send(tid[i], 100);
- }
- int response, child_tid, our_info;
- int var1, var2;
- chr = fgetc(handle);
- while(chr != EOF)
- {
- our_info = pvm_recv(-1, 200);
- pvm_bufinfo(our_info, &var1, &var2, &child_tid);
- pvm_upkint(&response, 1, 1);
- counter += response;
- pvm_initsend(PvmDataDefault);
- pvm_pkbyte(&chr, 1, 1);
- pvm_send(tid[0], 100);
- // printf("%d %d", child_tid, tid[0]);
- chr = fgetc(handle);
- }
- for (i = 0; i < 1; i++) {
- printf("%c\n", chr);
- int dane = pvm_recv(-1, 200);
- pvm_upkint(&response, 1 ,1);
- counter += response;
- int *bytes, *mstag, *tid_local;
- pvm_kill(*tid_local);
- }
- printf ("Odpowiedz z komputera %d\n", counter);
- pvm_exit();
- exit(0);
- }
- void childProgram()
- {
- int masterid;
- char sign;
- char name;
- int counter;
- int i;
- /* kto mnie stworzył */
- masterid = pvm_parent();
- while(1)
- {
- counter = 0;
- pvm_recv(masterid, 100);
- pvm_upkbyte(&name, 1, 1);
- i = 0;
- sign = name;
- if(sign == 'a')
- {
- counter++;
- }
- /* zwróć wyniki do procesu nadrzędnego */
- pvm_initsend(PvmDataDefault);
- pvm_pkint(&counter, 1, 1);
- pvm_send(masterid, 200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement