To calculate the possible speedup (Amdahl) I need the fraction of the parallelizable part of my code compared to the total sequential runtime.
I timed the execution using the chrono.h
library and got the total sequential runtime and parallelizable part runtime as chrono::duration
in nanoseconds.
Now I need to divide these two durations to get the percentage of possible parallelizable part.
e.g.
auto seqStartTime = std::chrono::steady_clock::now();
// Some code, non parallelizable
auto parStartTime = std::chrono::steady_clock::now();
// Parallelizable sequential code
auto parEndTime = std::chrono::steady_clock::now();
auto timeTakenPar = std::chrono::duration_cast<std::chrono::nanoseconds>(parEndTime - parStartTime);
// More sequential code possible
auto seqEndTime = std::chrono::steady_clock::now();
auto timeTakenSeq = std::chrono::duration_cast<std::chrono::nanoseconds>(seqEndTime - seqStartTime);
// auto frac = timeTakenPar / timeTakenSeq (??)
Any idea how to do that?
Simply dividing won't do the trick, since as far as I understood, this only returns the number of times the right hand side duration after conversion fits into the left hand side duration. In this case obviously zero, since the total runtime is on the rhs and parallelizable part runtime on the lhs.
I also tried using .count()
before dividing, but still ended up with 0 as result.
Any help is highly appreciated!