You don’t need CUDA or a loop to process this. The answer is zero for both result1 and result2.
In the more general case where you have initialized result1 and result2 to something other than zero (and, for completeness, lets assume your array is not a simple arithmetic sequence), this can be accomplished with a parallel reduction.
Considering the calculation for result1, the only difference from the typical treatise on parallel reduction:
is that you are taking the product in every case, instead of the sum. If you sort that out, I think the method to calculate result2 will be immediately obvious.
The information for reduction was very good - thank you.
I know that CUB has some operations for something similar - do you have any recommendation(s) regarding using CUB to reduce? Any sample/example code using CUB for the type of reduction(s) I am attempting would be greatly appreciated.
Thanks again for all help - it is greatly appreciated.
Unfortunately I can’t use thrust.
The one caveat that I have with regard to reduction, is that the array element can’t be modified - I suppose I could make a copy of the array and employ it for reduction but that seems like a lot of extra overhead?