Logo 
Search:

C Programming Articles

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

Program to solve the backward dependency for the following equation using crude way x[i]=x[i-1]+y[i]

Posted By: Leon Evans     Category: C Programming     Views: 2112

Program to solve the backward dependancy for the following equation using crude way x[i]=x[i-1]+y[i]

Code for Program to solve the backward dependency for the following equation using crude way x[i]=x[i-1]+y[i] in C Programming

#include<stdio.h>
#include "shared.h"
#include "forkjoin.h"int main()
{
        int *x, *y, size, i, j, nproc, pid;
        int sh1, sh2;

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

        printf("Enter the total number of processes :: ");
        scanf("%d", &nproc);

        x=(int *)create_memory(2*size, &sh1);
        y=(int *)create_memory(2*size, &sh2);        

        for(i=0;i<size;i++)
        {
                x[i]=i+1;
                y[i]=i;
        }

        pid=create_process(&nproc);

        for(i=pid;i<size;i+=nproc)
        {
                x[i]=x[0];
                for(j=1;j<=i;j++)
                        x[i]+=y[j];
        }

        join_process(&nproc, &pid);

        printf("\nThe modified array is :: ");
        for(i=0;i<size;i++)
                printf("\n%d",x[i]);

        cleanup_memory(&sh1);
        cleanup_memory(&sh2);              
        return 0;
}                     














/* OUTPUT */
Enter the size of the array :: 12 Enter the total number of processes :: 3 The modified array is :: 1 2 4 7 11 16 22 29 37 46 56 67
  
Share: 



Leon Evans
Leon Evans author of Program to solve the backward dependency for the following equation using crude way x[i]=x[i-1]+y[i] is from London, United Kingdom.
 
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!