#include<stdio.h>
#include "headfork.h"
#include "headbar.h"
#include "headshr.h"
main()
{
int *x,*xsav,*imin,*imax,*bar;
int shmid1,shmid2,shmid3,shmid4;
int npts,np,id,n,i;
x=shared(sizeof(int)*10,&shmid1);
xsav=shared(sizeof(int)*2,&shmid2);
imin=shared(sizeof(int)*2,&shmid3);
imax=shared(sizeof(int)*2,&shmid4);
printf("Enter the size of array: ");
scanf("%d",&n);
printf("Enter the array elements :\n");
for(i=1;i<=n;i++)
scanf("%d",(x+i));
printf("Enter the no.of proc :" );
scanf("%d",&np);
bar=bar_init(np);
id=p_fork(np);
npts=n/np;
if(id!=0)
imin[id]=id*npts;
else
imin[id]=1;
if(id!=(np-1))
imax[id]=(id+1)*npts-1;
else
imax[id]=n;
xsav[id]=x[imax[id]+1];
barrier(bar);
for(i=imin[id];i<=imax[id]-1;i++)
x[i]=x[i+1];
x[imax[id]]=xsav[id];
p_join(np,id);
printf(“After Forward dependency : “);
for(i=1;i<n;i++)
printf("\n%d",x[i]);
}
OUTPUT
knoppix@ttyp0[pp]$ cc frwd_shd_une.c
knoppix@ttyp0[pp]$ ./a.out
Enter the size of array: 10
Enter the array elements :
1
2
3
4
5
6
7
8
9
10
Enter the no.of proc :4
After Forward dependency :
2
3
4
5
6
7
8
9
10