Lab4 27150
Lab4 27150
Assignment No 4
Objective: Write a program for parallel vector dot product by using multithreading.
The complexity of vector dot product is O(N) and the execution time depends on the vector
length. In this assignment you will learn how to pass and return values from a thread and how
logically work can be divided into multiple threads to be performed in parallel and reduce total
execution time. You need do device some logic for load balancing. Use a Global variable for
result and protect it from concurrent access by using mutex and use condition variables if
desired.
Submit a word file containing all code, output snapshots and the comparison table and graph.
Also provide your logic for data distribution and computing.
-------------------------------------------------------------------------------------------------------------------------------
Input:
1. Vectors Length: N (to be used to create and initialize 2 vectors)
2. No of Threads: T
Processing: Determine the execution time of vector addition with various values of T and N
given in the table.
T0 = get clock cycle/system time
Perform DP = V2 . V3 with load balancing among T threads.
T1 = get clock cycle/system time
Time elapsed = T1 – T0
Output: Time elapsed - Tables show the comparison
N (vector size in thousands)
50 100 150 200 250 300 350 400
0.0004497 0.0007118 0.0009661 0.0010669 0.0013396 0.0021008 0.0024688 0.0022699
1
0.0005966 0.0004485 0.0006001 0.0006337 0.0005737 0.0007866 0.0010765 0.001463
5
0.0067447 0.0007338 0.0005418 0.0006967 0.000764 0.0011622 0.0009692 0.0017238
T (no of threads)
10
0.001867 0.0010221 0.0013049 0.0008869 0.0013156 0.0017345 0.0020449 0.0014512
15
0.0018874 0.0015366 0.0022029 0.0018583 0.0016797 0.0018984 0.0017549 0.0019093
20
0.0020552 0.0021941 0.0018118 0.0020087 0.0018274 0.0020094 0.0023893 0.0027231
25
0.0025019 0.0027168 0.0024938 0.0025832 0.0028481 0.0024068 0.0022032 0.0032359
30