The C++ DoWork1 routine below calculates the total of every number between 0 and 1000. Is there any way we can dynamically create 4 versions of this with each version counting a different quarter range i.e. 0-(250-1), 250-(500-1), 500-(750-1) and 750-1000 ?
void DoWork1() {
int n1 = 0;
int p1 = 0;
for (int p1 = 0; p1 <= 1000; p1++)
n1 = n1 + p1;
}
This is in preparation for an introduction to thread work with the ultimate aim of dynamically splitting the above routine into the max number of available threads to achieve the fastest execution time. I'm trying to keep things as simple as possible hence this basic routine as a starter. I understand there is potential for concurrency issues if using the same variables - I can look more into this once I see if there's a way to accomplish the above (unless the concurrency issue can be relatively easily overcome in this example).