TH-1: Array Summary
Sum a large array in C++ with and without multithreading, taking array size and thread count from the command line, and compare the timings.
Requirements
- Write a C++ program that creates an array of N elements (N > 1 000 000).
- Initialize the array with random values at the beginning.
- Compute summary of the array using a regular for loop and calculate the time spent for the operation.
- Create M threads to sum the same array with multiple threads, considering that every thread gets an equal portion to sum, except, maybe, the last one.
- Wait for all the threads to complete and measure the time spent for summing the array using M threads.
- Print the durations spent to sum the array with and without threads.
- Note that N and M variables should be passed to the program via command line arguments.
Expected result
The resulting application should be able to build and execute from command line as follows:
make
./array-summary 1000000 4and the command should print the output to the console as follows:
Time spent without threads: X
Time spent with M threads: YThe final solution should contain a Makefile for the multi-stage build. The Makefile should also contain targets all and clean. It's recommended to have compiler and compiler flags declared as Makefile variables. Alternatively, cmake could also be used instead of make.
PS-2: Interactive shell
Build an interactive C++ shell that spawns a process per command, adds the current directory to PATH, and redirects 'silent' commands to a PID.log file.
TH-2: Thread Pool
Build a C++ parallel_scheduler thread pool with a fixed capacity, enqueue functions for execution, and ship it as a shared library with a demo app.