From 90900d18be8a0b77eb736e622195eecaeaf93bbd Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Tue, 1 May 2012 21:58:57 +0200 Subject: GenericFD: Correct implementation of Sign Mathematica defines Sign(x) = Which[x>0, 1, x<0, -1, x==0, 0] whereas the current implementation in terms of copysign gives Sign(0) != 0. This causes problems when Sign is used to choose the finite differencing operator in boundary conditions. This commit restores the old definition in terms of the sgn function which we define now as static inline in GenericFD.h. --- Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c | 10 ---------- Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h | 6 +++++- .../KrancNumericalTools/GenericFD/src/MathematicaCompat.h | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) (limited to 'Auxiliary/Cactus') diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c index 1bd1a61..023e6e8 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.c @@ -49,16 +49,6 @@ /* TODO: provide functions for differencing, use FD macros to evaluate corresponding functions */ -int sgn(CCTK_REAL x) -{ - if (x < 0) - return -1; - else if (x > 0) - return 1; - else - return 0; -} - void GenericFD_GetBoundaryWidths(cGH const * restrict const cctkGH, int nboundaryzones[6]) { int is_internal[6]; diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h index 53e8035..217b931 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h @@ -54,7 +54,11 @@ extern "C" { #define KRANC_GFOFFSET3D(var,i,j,k) \ (*(CCTK_REAL const*)&((char const*)(var))[cdi*(i)+cdj*(j)+cdk*(k)]) -int sgn(CCTK_REAL x); +/* Implement the signum function, used for Mathematica's Sign function */ +static inline CCTK_REAL sgn(CCTK_REAL x) +{ + return x==(CCTK_REAL)0.0 ? (CCTK_REAL)0.0 : copysign((CCTK_REAL)1.0, x); +} int GenericFD_GetBoundaryWidth(cGH const * restrict const cctkGH); diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h index 252116c..28bcebc 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/MathematicaCompat.h @@ -40,11 +40,11 @@ #define Csch(x) (1.0/sinh(x)) #define Coth(x) (1.0/tanh(x)) +#define Sign(x) (sgn(x)) + #ifdef KRANC_C -# define Sign(x) (copysign( (CCTK_REAL) 1.0,(CCTK_REAL) (x))) # define ToReal(x) ((CCTK_REAL)(x)) #else -# define Sign(x) (sgn(x)) # define ToReal(x) (real((x),kind(khalf))) #endif -- cgit v1.2.3 From 9c0bc951b82e9e60b66cd48e2f8b34bd0007c4cd Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Wed, 2 May 2012 08:48:14 -0400 Subject: Add #include because of copysign() --- Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Auxiliary/Cactus') diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h index 217b931..65be7c5 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h @@ -30,6 +30,8 @@ #include "cctk.h" +#include + #ifdef __cplusplus extern "C" { #endif -- cgit v1.2.3 From b47ab113b482b752aef8201bcaa8a4a75ed59cd4 Mon Sep 17 00:00:00 2001 From: Ian Hinder Date: Wed, 2 May 2012 14:56:10 +0200 Subject: GenericFD: Provide annotation to sgn function for CUDA --- Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Auxiliary/Cactus') diff --git a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h index 65be7c5..6e3ed2b 100644 --- a/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h +++ b/Auxiliary/Cactus/KrancNumericalTools/GenericFD/src/GenericFD.h @@ -57,7 +57,14 @@ extern "C" { (*(CCTK_REAL const*)&((char const*)(var))[cdi*(i)+cdj*(j)+cdk*(k)]) /* Implement the signum function, used for Mathematica's Sign function */ -static inline CCTK_REAL sgn(CCTK_REAL x) + +#ifdef __CUDACC__ +#define KRANC_WHERE __device__ +#else +#define KRANC_WHERE +#endif + +KRANC_WHERE static inline CCTK_REAL sgn(CCTK_REAL x) { return x==(CCTK_REAL)0.0 ? (CCTK_REAL)0.0 : copysign((CCTK_REAL)1.0, x); } -- cgit v1.2.3