You are on page 1of 1

#include<omp.

h>
#include<stdio.h>
#include<stdlib.h>
#define CHUNKSIZE 10
5 # define N 10000

int main(){
int nthreads, tid, i, chunk;
int a[N];
10 int eSum = 0;
int oSum = 0;

for(i=0; i<=N;i++){
a[i] = i;
15 }
chunk = CHUNKSIZE;
omp_set_num_threads(32); // need to change this value
#pragma omp parallel shared(a, nthreads,chunk) private(i,tid)
{
20 tid = omp_get_thread_num();
printf("Thread %d is starting \n",tid);
#pragma omp for schedule(static, chunk) // need to change the schedule type
for(i=0;i<=N;i++){
if(a[i]%2 == 0){
25 eSum += a[i];
}else{
oSum += a[i];
}
printf("Thread %d: a[%d] = %d \n",tid,i,a[i]);
30 }
if(tid == 0){
nthreads = omp_get_num_threads();
printf("Number of threads= %d \n",nthreads);
printf("Number of Chunks: %d \n",chunk);
35 }
}
printf("Odd Sum: %d\n",oSum);
printf("Even Sum: %d\n",oSum);
}
40

You might also like