Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

SOLVE FOLLOWING EXPRESSION PARALLELY. X[k] = U[k] + r * ( Z[k] + r * U[k]) + t * ( U[k+3] + r * ( U[k+2] + r * U[k+1] ) )+ t * t * ( U[k+6] + r * ( U[

Posted By: Alfonsine Miller     Category: C Programming     Views: 2313

SOLVE FOLLOWING EXPRESSION PARALLELY. X[k] = U[k] + r * ( Z[k] + r * U[k]) + t * ( U[k+3] + r * ( U[k+2] + r * U[k+1] ) )+ t * t * ( U[k+6] + r * ( U[k+5] + r * U[k+4] ) )

Code for SOLVE FOLLOWING EXPRESSION PARALLELY. X[k] = U[k] + r * ( Z[k] + r * U[k]) + t * ( U[k+3] + r * ( U[k+2] + r * U[k+1] ) )+ t * t * ( U[k+6] + r * ( U[ in C Programming

#include "forkjoin.h"
#include "barrier.h"

main()
{
    int *x,*u,*z,r,t;
    int pid,nproc,*bar,shmid,shmid1,shmid2,shmid3,shmid4;
    int i,n,*sum;
    printf("Enter the no. of elements : ");
    scanf("%d",&n);
    x=(int *) create_memory(sizeof(int)*n,&shmid);
    u=(int *) create_memory(sizeof(int)*(n+6),&shmid1);
    z=(int *) create_memory(sizeof(int)*n,&shmid2);
    printf("Enter the value of array U\n");
    for(i=0;i<n+6;i++)
    {
        printf("Enter the valueof U[%d] : ",i+1);
        scanf("%d",&u[i]);
    }
    printf("\nEnter the value of array Z\n");
        for(i=0;i<n;i++)
        {
                printf("Enter the valueof Z[%d] : ",i+1);
                scanf("%d",&z[i]);
        }
    printf("\nEnter the value of r : ");
    scanf("%d",&r);
    printf("Enter the value of t : ");
    scanf("%d",&t);
    printf("\nEnter the no. of processes : ");
    scanf("%d",&nproc);
    bar=(int *) create_memory(sizeof(int),&shmid3);
    sum=(int *) create_memory(sizeof(int)*3,&shmid4);
    bar=barrier_init(333);
    pid=create_process(nproc);
    for(i=pid/3;i<n;i+=nproc/3)
    {
        if(pid%3 == 0)
            sum[pid]=r * (z[i] + r*u[i]); 
        elseif(pid%3==1)
            sum[pid]=t*(u[i+3] + r*(u[i+2] + r*u[i+1]));
        else
            sum[pid]=t*t*(u[i+6] + r*(u[i+5] + r*u[i+4]));
        barrier(bar);
        if(pid%3==0)
            x[i]=u[i]+sum[pid]+sum[pid+1]+sum[pid+2];
    }
    join_process(nproc,pid);
    printf("\nThe result is : ");
    for(i=0;i<n;i++)
        printf("%d\t",x[i]);
    clear_memory(&shmid);
    clear_memory(&shmid1);
    clear_memory(&shmid2);
    clear_memory(&shmid3);
    clear_memory(&shmid4);
}
  
Share: 



Alfonsine Miller
Alfonsine Miller author of SOLVE FOLLOWING EXPRESSION PARALLELY. X[k] = U[k] + r * ( Z[k] + r * U[k]) + t * ( U[k+3] + r * ( U[k+2] + r * U[k+1] ) )+ t * t * ( U[k+6] + r * ( U[ is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!