From 2efe9f77400296387584652e7b9b8a0af671c57b Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Fri, 21 Jul 2023 03:32:29 -0500 Subject: [PATCH 1/6] Create New_heat.jl New heat Method for improving the performance --- julia/heat/New_heat.jl | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 julia/heat/New_heat.jl diff --git a/julia/heat/New_heat.jl b/julia/heat/New_heat.jl new file mode 100644 index 0000000..aacf8eb --- /dev/null +++ b/julia/heat/New_heat.jl @@ -0,0 +1,55 @@ +using FastBroadcast +using BenchmarkTools + +# function of seting up the I.C. +function init_space(nx;nghost=1) + space = [collect(Float64,1:1:nx+2*nghost), collect(Float64,1:1:nx+2*nghost)] + return space +end + +function benchmark(nt::Int, space::Vector{Vector{T}}, nthreads::Int, nx::Int, α::T; nghost=1) where T + for t in range(1, nt) + # swap the array for next time iteration + ∂u∂t_next = isodd(t) ? space[1] : space[2]; + ∂u∂t = isodd(t) ? space[2] : space[1]; + # swap the periodic boundary + copyto!(view(∂u∂t, 1:nghost ), view(∂u∂t, nx+1:nx+nghost)); + copyto!(view(∂u∂t, nx+nghost+1:nx+2*nghost), view(∂u∂t, nghost+1:2*nghost )); + # Actual Advection + work!(∂u∂t_next, ∂u∂t, nx, α, nghost, nthreads) + end + ∂u∂t_next = isodd(nt) ? space[1] : space[2]; + return ∂u∂t_next +end + +function work!(∂uᵢ∂t_next::Array{T,1}, ∂uᵢ∂t::Array{T,1}, nx::Int, α::T, nghost::Int, nthreads::Int) where T + is, ie = nghost + 1 , nx + nghost + heat!(∂uᵢ∂t_next, ∂uᵢ∂t, α, is, ie, nthreads) + return nothing +end + +@inbounds function heat!(∂uᵢ∂t_next::Array{T,1}, ∂uᵢ∂t::Array{T,1}, α::T, is::Int, ie::Int, nthreads::Int) where T + @.. thread=true ∂uᵢ∂t_next[is:ie] = ∂uᵢ∂t[is:ie] + α * ( ∂uᵢ∂t[is-1:ie-1] - 2 * ∂uᵢ∂t[is:ie] + ∂uᵢ∂t[is+1:ie+1]) + return nothing; +end + +nx = parse(Int64,ARGS[3]) # number of nodes +k = 0.4 # heat transfer coefficient +dt = 1.0 # time step +dx = 1.0 # grid spacing +alpha = k*dt/(dx*dx) # alpha +nt = parse(Int64,ARGS[2]) # number of time steps +nthreads = parse(Int64,ARGS[1]) # number of threads + +totalTime = @belapsed benchmark($nt, space, $nthreads, $nx, $alpha) setup=(space=init_space($nx)) + +fn = "perfdata.csv" + +if isfile(fn) == false + file = open(fn, "w") + write(file, "lang,nx,nt,threads,dt,dx,total time,flops\n") + close(file) +end +file = open(fn, "a") +write(file, PROGRAM_FILE*","*string(nx)*","*string(nt)*","*string(nthreads)*","*string(dt)*","*string(dx)*","*string(totalTime)*","*string(0)*"\n") +close(file) From 68c6ad22196831a763ae9794d29e92971ed9a282 Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Fri, 21 Jul 2023 03:32:56 -0500 Subject: [PATCH 2/6] Create New_heat2 2nd Method to Improve the performance --- julia/heat/New_heat2 | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 julia/heat/New_heat2 diff --git a/julia/heat/New_heat2 b/julia/heat/New_heat2 new file mode 100644 index 0000000..82bf17f --- /dev/null +++ b/julia/heat/New_heat2 @@ -0,0 +1,51 @@ +using Polyester +using BenchmarkTools + +# function of seting up the I.C. +function init_space(nx;nghost=1) + space = [collect(Float64,1:1:nx+2*nghost), collect(Float64,1:1:nx+2*nghost)] + return space +end + +function benchmark(nt::Int, space::Vector{Vector{T}}, nthreads::Int, nx::Int, α::T; nghost=1) where T + for t in range(1, nt) + # swap the array for next time iteration + ∂u∂t_next = isodd(t) ? space[1] : space[2]; + ∂u∂t = isodd(t) ? space[2] : space[1]; + # swap the periodic boundary + copyto!(view(∂u∂t, 1:nghost ), view(∂u∂t, nx+1:nx+nghost)); + copyto!(view(∂u∂t, nx+nghost+1:nx+2*nghost), view(∂u∂t, nghost+1:2*nghost )); + # Actual Advection + work!(∂u∂t_next, ∂u∂t, nx, α, nghost) + end + ∂u∂t_next = isodd(nt) ? space[1] : space[2]; + return ∂u∂t_next +end + +function work!(∂uᵢ∂t_next::Array{T,1}, ∂uᵢ∂t::Array{T,1}, nx::Int, α::T, nghost::Int) where T + @batch per=core for i = nghost + 1 : nx + nghost + @inbounds ∂uᵢ∂t_next[i] = ∂uᵢ∂t[i] + α * (∂uᵢ∂t[i-1] - 2 *∂uᵢ∂t[i] + ∂uᵢ∂t[i+1]) + end + return nothing +end + +nx = parse(Int64,ARGS[3]) # number of nodes +k = 0.4 # heat transfer coefficient +dt = 1.0 # time step +dx = 1.0 # grid spacing +alpha = k*dt/(dx*dx) # alpha +nt = parse(Int64,ARGS[2]) # number of time steps +nthreads = parse(Int64,ARGS[1]) # number of threads + +totalTime = @belapsed benchmark($nt, space, $nthreads, $nx, $alpha) setup=(space=init_space($nx)) + +fn = "perfdata.csv" + +if isfile(fn) == false + file = open(fn, "w") + write(file, "lang,nx,nt,threads,dt,dx,total time,flops\n") + close(file) +end +file = open(fn, "a") +write(file, PROGRAM_FILE*","*string(nx)*","*string(nt)*","*string(nthreads)*","*string(dt)*","*string(dx)*","*string(totalTime)*","*string(0)*"\n") +close(file) From 9d813047cf2b741f3c8b939f29c47e07e8150752 Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Fri, 21 Jul 2023 03:33:17 -0500 Subject: [PATCH 3/6] Rename New_heat2 to New_heat2.jl --- julia/heat/{New_heat2 => New_heat2.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename julia/heat/{New_heat2 => New_heat2.jl} (100%) diff --git a/julia/heat/New_heat2 b/julia/heat/New_heat2.jl similarity index 100% rename from julia/heat/New_heat2 rename to julia/heat/New_heat2.jl From a6841bbed921db555627e27d163825a7a41aeb28 Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Mon, 31 Jul 2023 15:23:18 -0500 Subject: [PATCH 4/6] Update New_heat.jl License Added --- julia/heat/New_heat.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/julia/heat/New_heat.jl b/julia/heat/New_heat.jl index aacf8eb..44cd273 100644 --- a/julia/heat/New_heat.jl +++ b/julia/heat/New_heat.jl @@ -1,3 +1,9 @@ +# Copyright (c) 2023 AUTHORS +# +# SPDX-License-Identifier: BSL-1.0 +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + using FastBroadcast using BenchmarkTools From 77fdc0c4701279c8d12d62237b5a53af3115c3bf Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Mon, 31 Jul 2023 15:23:51 -0500 Subject: [PATCH 5/6] Update New_heat2.jl License Added --- julia/heat/New_heat2.jl | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/julia/heat/New_heat2.jl b/julia/heat/New_heat2.jl index 82bf17f..88c83fe 100644 --- a/julia/heat/New_heat2.jl +++ b/julia/heat/New_heat2.jl @@ -1,3 +1,9 @@ +# Copyright (c) 2023 AUTHORS +# +# SPDX-License-Identifier: BSL-1.0 +# Distributed under the Boost Software License, Version 1.0. (See accompanying +# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + using Polyester using BenchmarkTools From 6ec36adf61ec2cbea88c3779a6ce363b1b9208da Mon Sep 17 00:00:00 2001 From: Ka Wai HO Date: Mon, 31 Jul 2023 15:24:41 -0500 Subject: [PATCH 6/6] Update AUTHORS Authors added --- AUTHORS | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 41b8121..ca999a1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,3 +2,5 @@ Patrick Diehl (patrickdiehl@lsu.edu) Steven R. Brandt (sbrandt@cct.lsu.edu) Max Morris (mmor115@lsu.edu) Jeremiah Corrado (jeremiah.corrado@hpe.com) +Jamie Mair +Ka Wai HO (kho33@wisc.edu/ kawaiho@lanl.gov)