Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <time.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "pvm3.h"
  7.  
  8.  
  9. void rodzic()
  10. {
  11. int dlugosc;
  12.  char* tekst= "To jest ja test lab pvm rtgba";
  13. printf("Tekst: %s\n", tekst);
  14. dlugosc= strlen(tekst);
  15.  
  16.     struct pvmhostinfo *hostp;
  17.     int result, check, i, ilhost, ilarch, tid, tidmaster;
  18.     char bufor[64];
  19.  
  20.     //gethostname(bufor, 20);
  21.     //printf("Rodzic: %s\n", bufor);  //nazwa rodzica
  22.  
  23.  
  24.     if(tidmaster=pvm_mytid() <0) {
  25.         pvm_perror("enroll");
  26.         exit(1);
  27.     }
  28.  
  29.     pvm_config(&ilhost, &ilarch, &hostp);
  30.     printf(tekst);
  31.     tid = (int*) calloc (ilhost, sizeof(int));
  32.     for(i=0; i<ilhost; i++)
  33.     {
  34.         if(i>=dlugosc)
  35.             break;
  36.         check=pvm_spawn("/home/pvm/pvm3/lab/example", 0, PvmTaskHost, hostp[i].hi_name, 1, &tid);
  37.         pvm_initsend(PvmDataDefault);
  38.         pvm_pkbyte((tekst+i), 1, 1);
  39.         pvm_send(tid[i],100);
  40.        
  41.         if(!check)
  42.             printf("Błąd powołania potomka do życia na %s\n", hostp[i].hi_name);
  43.     }
  44.     result=0;
  45.     int liczba =0;
  46.     int count;
  47.     while(result<ilhost)
  48.     {
  49.         pvm_recv(-1, 200);
  50.         pvm_upkint(&count, 1, 1);
  51.         if(count==1)
  52.             liczba++;
  53.         result++;
  54.     }  
  55.     pvm_exit();
  56.     printf("Liczba znaków 'a': ", liczba);
  57. }
  58.  
  59. void potomek()
  60. {
  61.     char buf;
  62.     int m;
  63.     int charcount;
  64.    
  65.    
  66.     while(1)
  67.     {
  68.         pvm_recv(-1, 100);
  69.         pvm_upkbyte(&buf, 1, 1);
  70.        
  71.             if(buf == 'a') {
  72.              charcount=1;
  73.         }
  74.         int ptid=pvm_parent();
  75.         pvm_initsend(PvmDataDefault);
  76.         pvm_pkint(&charcount, 1, 1);
  77.         pvm_send(ptid, 200);
  78.     }
  79.  
  80.  
  81. }
  82.  
  83.  
  84. main()
  85. {
  86.     if(pvm_parent() == PvmNoParent)
  87.         rodzic();
  88.     else
  89.         potomek();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement