Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C. OpenMP (12.5 points each) Program 1 Assume that array is an array of size int values, but each value is a 1. What does

C. OpenMP (12.5 points each)

Program 1

Assume that array is an array of size int values, but each value is a 1. What does this print out when run on 4 threads? What does it run on 8 threads? Modify this code to get it to calculate and print out the actual sum of the values in the best possible way.

int sum =0;

# pragma omp parallel default ( none ) shared ( array , sum )

{

for ( int i =0; i < size ; i ++)

{

# pragma omp atomic

sum += array [ i ];

}

}

printf ( " total : %d " , sum );

Program 2

Use OpenMP for loop pragmas to parallelize this code as efficiently as possible. The only modifications you are allowed to do are pragmas. values is a std::vector.

for ( int i =1; i < values . size (); i ++)

{

values [ i] = values [i ]+ values [i -1];

}

for ( int i =0; i < values . size (); i ++)

{

for ( int j =0; j < array [i ]; j ++)

{

array [i] += sqrt ( j )*( i -j );

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago