Logo 
Search:

C Programming Articles

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

Program of solving the dependency in the linear recurrence relation x[i] = x[i-1] + y[i] using block scheduling

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

Write a program of solving the dependency in the linear recurrence relation x[i] = x[i-1] + y[i] using block scheduling.

Code for Program of solving the dependency in the linear recurrence relation x[i] = x[i-1] + y[i] using block scheduling 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"// included in zip
# include "sharedlib.h"// included in zip
# include "spinlock.h"// included in zip
# include "barrier.h"// included in zipint main()
{
    int arrSize=9;
    int *x;            
    int y[9];        
    int arrold[9];        // For Holding boundary Valuesint id;            // Process Identificationint nProc=3;        // Number of Processesint *bararr;        // Barrier Arrayint shmidbararr,shmidarr; // Shmid for Shared Variables//Calculating block Sizeint blocksize = arrSize/nProc;
    
    int index,iCount;
        
    x=(int*)sshared(sizeof(int)*10,&shmidarr);
        
    printf("Original Array ...\n");
    for(iCount=0;iCount<=arrSize;iCount++)
    {
        // Assigning X and Y Array Values
        x[iCount]=iCount;
        y[iCount]=iCount;
        printf("x[%d] : %d\t\ty[%d] : %d\n",iCount,x[iCount],y[iCount]);
    }
    
    bararr=(int*)sshared(sizeof(int)* 4,&shmidbararr);
    
    // Initialize Barrier Array    
    barrier_init(bararr,nProc);    
    
    id=process_fork(nProc);
    
    //Copying boundary values
    arrold[id]=x[blocksize*id];
            
    //Calling Barrier
    barrier(bararr);
    
    index=(id+1) * blocksize;
    
    for(iCount=index;iCount> index-blocksize;iCount--)
    {
        x[iCount]=x[iCount-1] + y[iCount];
    }

    // Taking Value from Stored Boundary Values    
    x[(id*blocksize)+1] = arrold[id] + y[(id*blocksize)+1];
    
    process_join(nProc,id);
        
    printf("After X[i] = X[i - 1] + y[i] ...\n");
    for(iCount=1;iCount<=arrSize;iCount++)
    {
        printf("X[%d] = %d\n",iCount,x[iCount]);
    }
    cleanup_memory(&shmidbararr);
    cleanup_memory(&shmidarr);
    return 0;
}
  
Share: 



Easy Tutor
Easy Tutor author of Program of solving the dependency in the linear recurrence relation x[i] = x[i-1] + y[i] using block scheduling 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] com

I 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

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!