I have two arrays A and B which have m and n int variables respectively. I have a function f, and I want to generate all f(a, b) which a is in A and b is in B:
A = {a1, a2, a3, ...., am}
B = {b1, b2, b3, ...., bn}
C = f(A * B) = {f(a1,b1), f(a1,b2), f(a1,b3), ..., f(a1, bn),
f(a2,b1), f(a2,b2), f(a1,b3), ..., f(a2, bn),
...
f(am,b1), f(am,b2), f(am,b3), ..., f(am, bn)}
More precisely, my function f is a simple bitwise or between numbers, but I wanted to ask it in general. Moreover, the order of the items in the result is not important. I only want to generate all possible pairs from A and B.
As I need to generate and store the result, how can I implement it efficiently (using C++ Cuda) to reduce the number of visiting the global memory? Do I need to use shared memory?
Any recommendation will be really appreciated.