 Search:

Submit Article

# Program of expression Splitting using multiple barriers

Posted By: Easy Tutor     Category: C Programming     Views: 3308

### Write a program of expression Splitting using multiple barriers. ## Code for Program of expression Splitting using multiple barriers in C Programming

```# include <stdio.h>
# include "/usr/include/sys/types.h"
# include "/usr/include/sys/shm.h"
# include "/usr/include/sys/ipc.h"
# include "/usr/include/sys/sem.h"
# include "forkjoin.h"
# include "sharedlib.h"
# include "spinlock.h"
# include "barrier.h"int main()
{
int iCount;
int nProc=10;
intconst n=19;
floatconst r=1,t=1;
int id,k,**bar_ary,**shmid;
float *x,y,u,z,*sum;

shmid=(int **)malloc(sizeof(int)* ((nProc-1)/2 +3) );

for(iCount=0;iCount< ((nProc-1)/2+3); iCount++)
{
shmid[iCount]=(int *)malloc(sizeof(int));
}

sum=(float *)malloc(sizeof(float)*20);
x=(float *)malloc(sizeof(float)*20);

sum=(float *)sshared(sizeof(float)*20,shmid);
x=(float *)sshared(sizeof(float)*20,shmid);

bar_ary=(int**)malloc(sizeof(int)*((nProc-1)/2 +2));

for(iCount=0; iCount <= ((nProc-1)/2); iCount++)
{
bar_ary[iCount]=(int *)malloc(sizeof(int)*5);
bar_ary[iCount]=(int *)sshared(sizeof(int)*5,shmid[iCount+2]);
}

for(iCount=0;iCount<27;iCount++)
{
u[iCount]=iCount+3;
if(iCount<20)
{
y[iCount]=iCount+1;
z[iCount]=iCount+2;
x[iCount]=0;
sum[iCount]=0;
}
}

for(iCount=0;iCount <= ((nProc-1)/2);iCount++)
{
barrier_init(bar_ary[1,iCount],2);
}

id=process_fork(nProc);

for(k=1+(id/2); k<n; k+=nProc/2)
{
if((id%2)==0)
{
sum[id]=u[k] + r * ( z[k] + r * y[k] ) + t * ( u[k+3] + r * u[k+2] );
}
else
{
sum[id]=t * r * r * u[k+1] + t * t * ( u[k+6] + r * ( u[k+5] + r * u[k+4] ));
}

barrier(bar_ary[1,id/2]);

if((id%2) == 0)
{
x[k]=sum[id]+sum[id+1];
}
barrier(bar_ary[1,id/2]);
}

process_join(nProc,id);

printf(" Results \n");
for(iCount=0; iCount<n ;iCount++)
{
printf(" x[%d]=%.2f \n",iCount,x[iCount]);
}

iCount=0;
while(iCount <  ((nProc-1)/2 + 3))
{
cleanup_memory(shmid[iCount]);
iCount++;
}
return 0;
}
```
Share:

Didn't find what you were looking for? Find more on Program of expression Splitting using multiple barriers Or get search suggestion and latest updates. Easy Tutor author of Program of expression Splitting using multiple barriers is from United States. Easy Tutor says Hello Friends,I am Free Lance Tutor, who helped student in completing their homework. I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] comI have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada. I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.Thanks,Happy Programming :) View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!