Forked from pkestene/gist:933ce4770e462c80908bf72f7a0ef150
Created
June 28, 2018 07:28
-
-
Save maxlevesque/a5c3ec08ddd8726682a2ae7c1a92235b to your computer and use it in GitHub Desktop.
index2coord
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 2D */ | |
KOKKOS_INLINE_FUNCTION | |
void index2coord(int index, int &i, int &j, int Nx, int Ny) | |
{ | |
UNUSED(Nx); | |
UNUSED(Ny); | |
#ifdef KOKKOS_ENABLE_CUDA | |
j = index / Nx; | |
i = index - j*Nx; | |
#else | |
i = index / Ny; | |
j = index - i*Ny; | |
#endif | |
} | |
KOKKOS_INLINE_FUNCTION | |
int coord2index(int i, int j, int Nx, int Ny) | |
{ | |
UNUSED(Nx); | |
UNUSED(Ny); | |
#ifdef KOKKOS_ENABLE_CUDA | |
return i + Nx*j; // left layout | |
#else | |
return j + Ny*i; // right layout | |
#endif | |
} | |
/* 3D */ | |
KOKKOS_INLINE_FUNCTION | |
void index2coord(int index, | |
int &i, int &j, int &k, | |
int Nx, int Ny, int Nz) | |
{ | |
UNUSED(Nx); | |
UNUSED(Nz); | |
#ifdef KOKKOS_ENABLE_CUDA | |
int NxNy = Nx*Ny; | |
k = index / NxNy; | |
j = (index - k*NxNy) / Nx; | |
i = index - j*Nx - k*NxNy; | |
#else | |
int NyNz = Ny*Nz; | |
i = index / NyNz; | |
j = (index - i*NyNz) / Nz; | |
k = index - j*Nz - i*NyNz; | |
#endif | |
} | |
KOKKOS_INLINE_FUNCTION | |
int coord2index(int i, int j, int k, | |
int Nx, int Ny, int Nz) | |
{ | |
UNUSED(Nx); | |
UNUSED(Nz); | |
#ifdef KOKKOS_ENABLE_CUDA | |
return i + Nx*j + Nx*Ny*k; // left layout | |
#else | |
return k + Nz*j + Nz*Ny*i; // right layout | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment