Giter Site home page Giter Site logo

Make CellArrays mutable about parallelstencil.jl HOT 4 OPEN

omlins avatar omlins commented on May 30, 2024
Make CellArrays mutable

from parallelstencil.jl.

Comments (4)

omlins avatar omlins commented on May 30, 2024

@TakeTwiceDailey :

first of all, to be sure that we are on the same page, note that @CellType and the celldims key word of the allocator functions rely on the package CellArrays which defines the type CellArray.

CellArray creates the StaticArray cells on the fly when accessed. Mutable StaticArrays cannot be created in GPU kernels as they would require heap allocation (besides, performance would certainly be terrible in this use case). Thus, only immutable types are used. Nevertheless, CellArrays' content is mutable. The following example shows three ways of content mutation (the example does not use ParallelStencil, but the same applies also in this case):

using CellArrays, StaticArrays

function main_CellArrays()
    nel      = 2
    celldims = (3, 3)
    Cell     = SMatrix{celldims..., Float64, prod(celldims)}
    C        = CPUCellArray{Cell}(undef, nel) 
    C.data  .= 0.0

    # The aims is to change te values of each 3x3 matrix
    # 1 - with a double loop for each element: it works
    for e=1:nel
        for i=1:celldims[1]
            for j=1:celldims[2]
                field(C,i,j)[e] = 1.0
            end
        end
    end
    @show C

    # 2 - assigning cell by cell
    for e=1:nel
        C[e] = Cell(ones(celldims))
    end
    @show C
    
    # 3 - assiging all data at once
    C.data .= 9.0
    @show C
end
main_CellArrays()

Check out the documentation of CellArrays for more information.

Also, it would be nice to have the CellType act as the tensor it is meant to represent, while still only storing the needed values. For example, defining @CellType SymmetricTensor2D fieldnames=(xx, zz, xz) I could then overload getindex
(...)

I think i think it should work to create an alternative indexing on top of the indexing created by @CellType. If you can work something out that is robust and performance, then we would be happy for a pull request in CellArrays.jl for this additional functionality on top of the existing functionality.

from parallelstencil.jl.

TakeTwiceDailey avatar TakeTwiceDailey commented on May 30, 2024

@omlins

Thanks, I understand much better how CellArrays is meant to work now.

I find too often I try to reinvent the wheel. When in doubt, someone smarter in Julia than I has thought of these things.

For my purposes, storing the state vector of my system of equations in a StructArray from StructArrays.jl with elements of type Tensor from Tensorial.jl has all of the functionality I want, and the storage and access efficiency has been optimized behind the scenes.

from parallelstencil.jl.

omlins avatar omlins commented on May 30, 2024

@TakeTwiceDailey: StructArray from StructArrays.jl performs very badly on GPU (and I also ran into some errors on GPU). This is actually the very reason why I created the package CellArrays (I had first experimented with StructArrays and did some performance tests on GPU). If you only want to run on CPU, then both performance and functionality of StructArray should be good.

from parallelstencil.jl.

TakeTwiceDailey avatar TakeTwiceDailey commented on May 30, 2024

@omlins Oh, I see.

I would certainly like to run on a GPU at some point, but I have many problems to surmount before what I want to do is working on the CPU.

If I were to run this on the GPU, we would not only need to make CellArrays act like tensors, we would need to make @einsum work properly on them as well. I'm afraid I am not a software developer in any sense, so a lot of this machinery is way over my head.

from parallelstencil.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.