Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <chrono>


using namespace std::chrono;
using namespace std;

void randomVector(int vector[], int size)
{
for (int i = 0; i < size; i++)
{
//ToDo: Add Comment
vector[i] = rand() % 100;
}
}


int main(){

unsigned long size = 100000000;

srand(time(0));

int *v1, *v2, *v3;

//ToDo: Add Comment
auto start = high_resolution_clock::now();

//ToDo: Add Comment
v1 = (int *) malloc(size * sizeof(int *));
v2 = (int *) malloc(size * sizeof(int *));
v3 = (int *) malloc(size * sizeof(int *));


randomVector(v1, size);

randomVector(v2, size);


//ToDo: Add Comment
for (int i = 0; i < size; i++)
{
v3[i] = v1[i] + v2[i];
}

auto stop = high_resolution_clock::now();

//ToDo: Add Comment
auto duration = duration_cast<microseconds>(stop - start);


cout << "Time taken by function: "
<< duration.count() << " microseconds" << endl;

return 0;
}

Complete the code by adding appropriate comments in the designated lines. Develop a roadmap to parallelise this program. You should start with decomposition of the
program/problem into sub-tasks - i.e. partitioning data/tasks. Document your list of sub-tasks or
activities you plan to do in parallel vs activities that need to be in sequence. Implement your parallel algorithm in C or C++ using pthread or std::thread library. Evaluate the performance of your program (using execution time as a metric), to assess the speed up achieved. Compare the results with the sequential program. Varry the partition size and analyse how it can impact the executing time of the program.

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education