Posts

Showing posts with the label openMP

Matrix and Vector Multiplication In C using OpenMP Model

Image
This is a program which will multiply a vector and a matrix and display it. Basically a 1D Dynamic array and another 2D Dynamic array gets created and values are automatically assigned to it using the rand().  Here, OpenMP model is used for parallel computation of the task. Screenshot The Code: #include<stdio.h> #include<malloc.h> #include<omp.h> #include<time.h> int main() { int **a,n,i,j,*b,*c,k; clock_t st,en; double t; printf("Enter the N: "); scanf("%d",&n); // For the A Matrix a=(int**)malloc(sizeof(int*)*n); for(i=0;i<n;i++) a[i]=(int*)malloc(sizeof(int)*n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { a[i][j]=rand()/100000000; } } //For the B Matrix b=(int*)malloc(sizeof(int)*n); for(i=0;i<n;i++) b[i]=rand()/100000000; //For The C Matrix c=(int*)malloc(sizeof(int)*n); for(i=0;i<n;i++) c[i]=0; printf("The A MAtrix :\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { ...

Addition of Two Matrix By OpenMP Model

Image
This is a program in which the user gives the Number of Elements as input, then from that input 3 dynamic arrays are created in which first two are assigned with random values. Using the OpenMP model, the addition is distributed among different threads and then the addition of the above matrix is done and finally stored in the third Matrix. Screenshots [DEMO] The Code #include<stdio.h> #include<stdlib.h> #include<malloc.h> #include<omp.h> int main() { int *a,*b,*c,i,N; printf("Enter The No of Elements for both arrays: "); scanf("%d",&N); a=(int*)malloc(sizeof(int)*N); b=(int*)malloc(sizeof(int)*N); c=(int*)malloc(sizeof(int)*N); for(i=0;i<N;i++) { //scanf("%d",&a[i]); a[i]=rand()/100000; } for(i=0;i<N;i++) { b[i]=rand()/100000; //scanf("%d",&b[i]); } printf("A[%d]:\t",N); for(i=0;i<N;i++) { printf("%d ",a[i]); //a[i]=rand(); } printf("\n...

OpenMP, Parallel Programming in C [Intro]

Image
This is a post in which you will get the basic knowledge about the parallel programming concept. In this post we going to use the OpenMP model. This program is implemented in the C Language. Basically this programs demonstrates how the thread gets executed in different Cores of the processor. In this case, this program is executed in a Quad Core CPU, so it displays 4 threads from 0-3. Screenshots[Demo] Here the threads are executed randomly on each cores on the basics of their availability. This method by which threads get their processor can be known in detail by googling about ready queue. The Code: #include<stdio.h> #include<omp.h> int main() { int x; #pragma omp parallel { x=omp_get_thread_num(); printf("Thread Is running at %dth processor\n",x); } return 0; } Got Suggestions? Comment them here !