This example attempts to show use of the parallel for construct. However it will
ID: 3747422 • Letter: T
Question
This example attempts to show use of the parallel for construct. However it will generate errors at compile time. Try to determine what is causing the error.
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define N 10
#define CHUNKSIZE 2
int main (int argc, char *argv[])
{
int i, chunk, tid;
float a[N], b[N], c[N];
/* Some initializations */
for (i=0; i < N; i++)
a[i] = b[i] = i * 1.0;
chunk = CHUNKSIZE;
#pragma omp parallel for
shared(a,b,c,chunk)
private(i)
schedule(static,chunk)
{
tid = omp_get_threads_num();
for (i=0; i < N; i++)
{
c[i] = a[i] + b[i];
printf("tid= %d i= %d c[i]= %f ", tid, i, c[i]);
}
} /* end of parallel for construct */
}
#include #include #include #define N #de fine CHUNKS I ZE 10 2 int main (int argc, char argv[]) int i, chunk, tid; float a [N], b[N], c[N]; /*Some initializations / for (iF0 iExplanation / Answer
#include<omp.h>
#include<stdio.h>
#include<stdlib.h>
#define CHUNKSIZE 10
#defibe N 100
int main ( int argc, char *argv[ ] )
{
Int nthreads, tid, i, chunk;
float a[N], b[n], c[N];
/*some intializations */
for(i=0; i<N; i++)
a[i] = b[i] = i*1.0;
chunk = CHUNKSIZE;
#pragma omp parallel
shared(a, b, c, nthreads, chunk)
Private(i, tid )
{
tid = omp_get_thread_num() ;
if ( tid==0)
{
nthreads = omp _get_num_threads() ;
printf(" number of threads = %d ", nthreads) ;
}
printf("thread %don't starting... ", tid) ;
#pragma omp for schedule( dynamic, chunk)
for(i=0; i<N; i++)
{
c[i] = a[i] + b[i] ;
Printf("thread %d: c[%d] = %f ", tid, i, c[i]) ;
}
} /* end of parallel section*/
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.