Logo 
Search:

C Programming Articles

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

Program to overcome the forward dependency using block scheduling using the most equitable distribution of work

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

Write a program to overcome the forward dependency using block scheduling using the most equitable distribution of work (i.e. considering excess points).

Code for Program to overcome the forward dependency using block scheduling using the most equitable distribution of work 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 arrSize=11;
    int *arr;
    int arrold[11];            // For Holding boundary Cellsint minIndex[11];        // For Holding the Start of Each Blockint maxIndex[11];        // For Holding the End of Each Blockint id;                // Process Identificationint nProc=3;            // Number of Processesint *bararr;            // Barrier Arrayint shmidbararr,shmidarr;    // shmid for Shared Variablesint blocksize = arrSize / nProc;    // Calculating Block Sizeint index,iCount;    
    
    // Calculating excesspoints// When Number of Array Elements to Process not divisible by // Number of Processes, excesspoints occursint excesspoints=arrSize - (blocksize * nProc);
    
    arr=(int*)sshared(sizeof(int)*10,&shmidarr);
    
    printf("Number of Processes : %d\n",nProc);
    printf("Number of Excesspoints      : %d\n",excesspoints);
    
    printf("Original Array ...\n");    
    for(iCount=1;iCount<=arrSize+1;iCount++)
    {
        arr[iCount]=iCount;    // Assigning Array Values
        printf("arr[%d] : %d\n",iCount,arr[iCount]);
    }
    bararr=(int*)sshared(sizeof(int)* 4,&shmidbararr);    
    
    // Initialize Barrier Array
    barrier_init(bararr,nProc);
            
    id=process_fork(nProc);
    
    if(excesspoints ==0)
    {
        // if no excesspoints
        minIndex[id]=(id * blocksize) + 1;
        maxIndex[id]=(id * blocksize) + blocksize;
    }
    else
    {        
        if(id < excesspoints)        
        {
        // Process From ID 0 to (excesspoints-1) Will handle 1 more element,// So that there is most equitable distribution of  work
            minIndex[id]=(id * (blocksize + 1)) + 1;
            maxIndex[id]=minIndex[id] + blocksize;
        }
        else
        {
            minIndex[id]=(id * blocksize) + 1 + excesspoints;
            maxIndex[id]=minIndex[id] + blocksize - 1;
        }
        
    }
    
    
    // Copying Boundary Values
    arrold[id] = arr[maxIndex[id]+1];
    
    // Calling Barrier        
    barrier(bararr);

                
    for(iCount=minIndex[id];iCount<maxIndex[id];iCount++)
    {
        arr[iCount]=arr[iCount+1];
    }

    // Assigning Boundary Values
    arr[maxIndex[id]] = arrold[id];
        
    process_join(nProc,id);
    
    printf("After Copy ...\n");
    for(iCount=1;iCount<=arrSize;iCount++)
    {
        printf("arr[%d] = %d\n",iCount,arr[iCount]);
    }
    cleanup_memory(&shmidbararr);
    cleanup_memory(&shmidarr);
    return 0;
}
  
Share: 



Easy Tutor
Easy Tutor author of Program to overcome the forward dependency using block scheduling using the most equitable distribution of work 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!