#include<stdio.h>
#include "shared.h"
#include "forkjoin.h"int main()
{
int *x, *y, size, i, j, nproc, pid;
int sh1, sh2;
printf("Enter the size of the array :: ");
scanf("%d", &size);
printf("Enter the total number of processes :: ");
scanf("%d", &nproc);
x=(int *)create_memory(2*size, &sh1);
y=(int *)create_memory(2*size, &sh2);
for(i=0;i<size;i++)
{
x[i]=i+1;
y[i]=i;
}
pid=create_process(&nproc);
for(i=pid;i<size;i+=nproc)
{
x[i]=x[0];
for(j=1;j<=i;j++)
x[i]+=y[j];
}
join_process(&nproc, &pid);
printf("\nThe modified array is :: ");
for(i=0;i<size;i++)
printf("\n%d",x[i]);
cleanup_memory(&sh1);
cleanup_memory(&sh2);
return 0;
}
/* OUTPUT */
Enter the size of the array :: 12
Enter the total number of processes :: 3
The modified array is ::
1
2
4
7
11
16
22
29
37
46
56
67