MPI code for computing the dot product of vectors on p processors using block-striped partitioning for uniform data distribution.
Assuming that the vectors are of size n and p is number of processors used and n is a multiple of p.
Algebraically, the dot product is the sum of the products of the corresponding entries of the two sequences of numbers.
Let vector A be
[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]
Let vector B be
[ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ]
Output:
[ 1.0 + 4.0 + 9.0 + 16.0 + 25.0 + 36.0 + 49.0 + 64.0 ] = 204.0
Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
CPU(s): 8
Thread(s) per core: 2
$ mpic++ main.cpp -o exc
$ mpirun -np 4 exc