Professional Documents
Culture Documents
ANSH GOYAL
17BCE1278
LAB-5
#include<stdio.h>
#include<omp.h>
void main(){
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
int i,j,k;
#pragma omp parallel for collapse(2) shared(first,second,multiply)
private(i,j,k)
Output:
2. Addition of 1-D array elements using reduction.
Code:
#include<stdio.h>
#include<omp.h>
void main()
{
int a[100], n,i,total_sum=0;
printf("Enter number of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d", &a[i]);
#pragma omp parallel for reduction(+:total_sum)
for(i=0;i<n;i++)
{
total_sum+=a[i];
}
printf("total sum of 1-D array is= %d\n",total_sum);
}
Output: