Saturday, 26 January 2013


Aim: Finding sum of an array using Parallel Reduction
MSc IT Parallel Processing Practical No. 10
Index of all Practicals ~ Click Here

Code:
#include<stdio.h>
#include"shmlib.h"
int main()
{
int *result,num[6],x,id1,id,val,i,final;
                  
result=(int *) shared(sizeof(int),&id1);

printf("Enter values");                                     

for(x=0;x<6;x++)
{
scanf("%d",&num[x]);
}
id=create_process(2);

if(id==0)
{
result[0]=num[0]+num[1];
}
if(id==1)
{
result[1]=num[2]+num[3];
}

if(id==2)
{
result[2]=num[4]+num[5];
}
join_process(3,id);

id=create_process(0);

if(id==0)
{
result[3]=result[0]+result[1];
}

join_process(1,id);

result[4]=result[3]+result[2];



printf("the parallely reduced value is %d",result[4]);   

return 0;
}

Output:

Related Posts :



0 comments:

Confused? Feel free to ask

Post a Comment