Git Product home page Git Product logo

Comments (2)

willow-ahrens avatar willow-ahrens commented on August 28, 2024 2

For newcomers to this issue, the idea is as follows:
Say we're using a really simple time stepper to update the velocity of the particles stored in a vector v. To start out, we could initialize the vector v as:

v = zeros(Float64, 3, nparticles)
dvdt = rand(3,3)
dt = 0.5

Then the time stepper could be written as:

for i in eachindex(v)
  v[1, i] += dvdt[1] #X coordinate of velocity
  v[2, i] += dvdt[2] #Y coordinate of velocity
  v[3, i] += dvdt[3] #Z coordinate of velocity
end

We could collapse this with another for-loop like

for i in eachindex(v)
  for pos in 1:3
  v[pos, i] += dvdt[pos] #X coordinate of velocity
end

but in Julia, we can do better. Suppose instead we initialize our array of velocities as precisely that: an array of velocity vectors. Note that we are using SVectors so the compiler will make our tiny loops unroll and be fast.
We would initialize as

using StaticArrays
v = zeros(SVector{3, Float64}, 3, nparticles)
dvdt = SVector{3, Float64}(rand(3))
dt = 0.5

Then we can write our loop as

for i in eachindex(v)
  v[i] += dvdt * dt #forward euler step of velocity
end

This works because + is defined on two vector types and * is defined between scalar and vector types! Way cool!

from climatemachine.jl.

lcw avatar lcw commented on August 28, 2024

Right now we are waiting for JuliaGPU/CUDAnative.jl#340 before we can start creating device arrays.

from climatemachine.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.