Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Mateusz Pindel
- #include <stdio.h>
- #include <stdlib.h>
- double licz (int i,int n){
- return ((i*i-12)*(i*i-12)*(i*i-12))/(n*n*n*i*i*i);
- }
- int main(int argc, char *argv[]){
- double dataFromPipe;
- double sum = 0;
- double a;
- int i = 0, n, k;
- int countElementsByProces;
- int isChild;
- int potok[2];
- pipe(potok);
- if( argc != 3 ) printf("Bledna ilosc parametrow");
- else {
- n = atoi(argv[1]);
- printf("Ilosc elementow: %d\n", n);
- k = atoi(argv[2]);
- printf("Ilosc procesow potomnych: %d\n", k);
- printf("\n");
- }
- countElementsByProces = n / k;
- while ( isChild != 0 && i < k){
- isChild = fork();
- i++;
- }
- // dziecko
- if( isChild == 0 ) {
- double tmpsum = 0;
- printf ("Proces potomny: %d\t", i);
- int j = i;
- for(j; j <= n; j += k)
- {
- tmpsum += licz(j, n);
- }
- printf("Obliczona suma procesu potomnego: %f\n", tmpsum);
- write(potok[1], &tmpsum, sizeof(double));
- exit(0);
- }
- // rodzic
- else
- {
- for(i=0; i < k; i++)
- {
- read(potok[0], &a, sizeof(double));
- sum = sum + a;
- }
- printf("\n\nSuma calkowita: %f", sum);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement