Logo 
Search:

C Programming Articles

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

PROGRAM FOR FORWARD SCHEDULING FOR EQUAL DISTRIBUTION

Posted By: Verner Fischer     Category: C Programming     Views: 1940

WRITE A PROGRAM FOR FORWARD SCHEDULING FOR EQUAL DISTRIBUTION.

Code for PROGRAM FOR FORWARD SCHEDULING FOR EQUAL DISTRIBUTION in C Programming

#include<stdio.h>
#include "headfork.h"// included in attchment
#include "headbar.h"
#include "headshr.h"

main()
{
    int *x,*xsav,*imin,*imax,*bar;
    int shmid1,shmid2,shmid3,shmid4;
    int npts,np,id,n,i,excess;

    x=shared(sizeof(int)*10,&shmid1);
    xsav=shared(sizeof(int)*2,&shmid2);
    imin=shared(sizeof(int)*2,&shmid3);
    imax=shared(sizeof(int)*2,&shmid4);

    printf("Enter the size of array: ");
    scanf("%d",&n);

    printf("Enter the array elements :\n");
    for(i=1;i<=n;i++)
        scanf("%d",(x+i));

    printf("Enter the no.of proc :" );
    scanf("%d",&np);

    bar=bar_init(np);

    id=p_fork(np);
    
    npts=n/np;

    excess=n-(np*npts);

    if(excess==0)
    {
        imin[id]=id*npts+1;
        imax[id]=id*npts+npts;
    }
    else
    {
        if(id<excess)
        {
            imin[id]=id*(npts+1)+1;
            imax[id]=imin[id]+npts;
        }
        else
        {
            imin[id]=id*npts+1+excess;
            imax[id]=imin[id]+npts-1;
        }
    }

    xsav[id]=x[imax[id]+1];

    barrier(bar);

    for(i=imin[id];i<=imax[id]-1;i++)
        x[i]=x[i+1];

    x[imax[id]]=xsav[id];

    p_join(np,id);

    for(i=1;i<n;i++)
        printf("\n%d",x[i]);
}
  
Share: 


Didn't find what you were looking for? Find more on PROGRAM FOR FORWARD SCHEDULING FOR EQUAL DISTRIBUTION Or get search suggestion and latest updates.

Verner Fischer
Verner Fischer author of PROGRAM FOR FORWARD SCHEDULING FOR EQUAL DISTRIBUTION is from Frankfurt, Germany.
 
View All Articles

 
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!