Aim: Create 2 processes, process 1 should do the sum0 and process 2 should do sum1.Using shared memory concept add sum0 + sum1.
MSc IT Parallel Processing Practical No. 2
Index of all Practicals ~ Click Here
Code:
Output:
MSc IT Parallel Processing Practical No. 2
Index of all Practicals ~ Click Here
Code:
#include<stdio.h>
#include "shmlib.h"
int main()
{
int final_sum,*sum0,*sum1,id,id1,id2;
sum0=(int *)shared(sizeof(int),&id1);
sum1=(int *)shared(sizeof(int),&id2);
id=create_process(1);
if(id==0)
{
*sum0=3+5;
printf("\n sum0 : %d ",*sum0);
}
if(id==1)
{
*sum1=8+9;
printf("\n sum1 : %d ",*sum1);
}
join_process(2,id);
final_sum=*sum0+*sum1;
printf("\n Final result is : %d ",final_sum);
printf("\n");
free_shm(id1);
free_shm(id2);
return 0;
}
#include "shmlib.h"
int main()
{
int final_sum,*sum0,*sum1,id,id1,id2;
sum0=(int *)shared(sizeof(int),&id1);
sum1=(int *)shared(sizeof(int),&id2);
id=create_process(1);
if(id==0)
{
*sum0=3+5;
printf("\n sum0 : %d ",*sum0);
}
if(id==1)
{
*sum1=8+9;
printf("\n sum1 : %d ",*sum1);
}
join_process(2,id);
final_sum=*sum0+*sum1;
printf("\n Final result is : %d ",final_sum);
printf("\n");
free_shm(id1);
free_shm(id2);
return 0;
}
Output:
0 comments:
Confused? Feel free to ask
Post a Comment