WHERE Construct in CUDA Code

Simple question. I’m going to soon work on moving some code to the GPU that uses the WHERE/ELSEWHERE construct liberally (often, say, to prevent division-by-zero):

  where( QA > 0.0 )
    fQi_A = QAi / QA
    fQi_A = 0.0

My question is, is WHERE/ELSEWHERE supported in CUDA Fortran or will I need to translate them into IF blocks? (My guess is that I’ll have to since the GPUs require more explicit knowledge of program flow than this construct.)


Hi Matt,

The WHERE statement should work within device code. I just tried it with a simple case and it seemed fine. Though, I would avoid using it on global arrays for performance reasons.

  • Mat

Sounds good, thanks.

Just out of curiosity, is there a good CUDA Fortran equivalent to WHERE someone has come up with? Say with warp-vote operators or something? WHERE is just so elegant…