From 72b06dea00698ae011db1e723a56e396e19bc9a5 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Mon, 7 Oct 2019 07:03:31 -0400 Subject: [PATCH 1/2] fix complex adaptive norms on GPU --- src/common_defaults.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common_defaults.jl b/src/common_defaults.jl index 71fc6c4f8..fe7353e4c 100644 --- a/src/common_defaults.jl +++ b/src/common_defaults.jl @@ -1,12 +1,12 @@ -@inline UNITLESS_ABS2(x) = Real(abs2(x)/(typeof(x)(one(x))*typeof(x)(one(x)))) +@inline UNITLESS_ABS2(x) = real(abs2(x)/(typeof(x)(one(x))*typeof(x)(one(x)))) @inline ODE_DEFAULT_NORM(u::Union{AbstractFloat,Complex},t) = abs(u) @inline ODE_DEFAULT_NORM(u::Array{T},t) where T<:Union{AbstractFloat,Complex} = - @fastmath sqrt(sum(abs2,u) / length(u)) + @fastmath sqrt(real(sum(abs2,u)) / length(u)) @inline ODE_DEFAULT_NORM(u::RecursiveArrayTools.AbstractVectorOfArray,t) = - sum(sqrt(sum(UNITLESS_ABS2,_u) / length(_u)) for _u in u.u) -@inline ODE_DEFAULT_NORM(u::AbstractArray,t) = sqrt(sum(UNITLESS_ABS2,u) / length(u)) -@inline ODE_DEFAULT_NORM(u::AbstractArray{T,N},t) where {T<:AbstractArray,N} = sqrt(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip(u,t)) / length(u)) + sum(sqrt(real(sum(UNITLESS_ABS2,_u)) / length(_u)) for _u in u.u) +@inline ODE_DEFAULT_NORM(u::AbstractArray,t) = sqrt(real(sum(UNITLESS_ABS2,u)) / length(u)) +@inline ODE_DEFAULT_NORM(u::AbstractArray{T,N},t) where {T<:AbstractArray,N} = sqrt(real(sum(x->ODE_DEFAULT_NORM(x[1],x[2]),zip(u,t))) / length(u)) @inline ODE_DEFAULT_NORM(u,t) = norm(u) @inline ODE_DEFAULT_ISOUTOFDOMAIN(u,p,t) = false From e80cb01c775a0c7a09089a7a7561d2e459b678c8 Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Mon, 7 Oct 2019 07:06:11 -0400 Subject: [PATCH 2/2] add gpu complex number adaptivity test --- test/gpu/simple_gpu.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/gpu/simple_gpu.jl b/test/gpu/simple_gpu.jl index 7ed1963ba..aa863cbdb 100644 --- a/test/gpu/simple_gpu.jl +++ b/test/gpu/simple_gpu.jl @@ -55,3 +55,9 @@ u0 = [1.0;0.0;0.0] tspan = (0.0,100.0) prob_num = ODEProblem(ff2,u0,tspan) sol = solve(prob_num,Rosenbrock23(linsolve=LinSolveGPUFactorize())) + +# Complex Numbers Adaptivity DifferentialEquations.jl#460 +f_complex(u,nothing,t) = 1/2 .*u +u0 = cu(rand(32,32).+ 1im*rand(32,32)); +prob = ODEProblem(f_complex,u0,(0.0,1.0)) +sol = solve(prob,Tsit5())