Best practice to use lots of pre-allocated arrays in a function

Iddingsite
Thu, 03 Mar 2022 13:18:01 +0000
General Usage

I am still quite new to Julia, working on numerical modeling and I am starting to write a bigger project than usual.

I have a function that takes, as arguments, lots of pre-allocated arrays and parameters and update them in different ways using different functions. I am wondering what would be the best practice to store them and update them?

In pseudocode:

array1 = zeros(nx)
array2 = zeros(nx)
array3 = zeros(nx)
...

function update!(array1, array2, array3,...., parameters)
    updatearray1!(array1, parameters..)
    updatearray2!(array2, parameters..)
    updatearray3!(array3, parameters..)
end

What bother me here is that I have lots of arguments for my function. I was wondering what is the common practice for storing pre-allocated arrays?

My idea would be to store them all in an array, input that in the function, and use @view at the beginning of the function for each separate array, and inputing that in the internal functions. Is there a better way to do that?

I have started to work with Parameters.jl for storing the constant of my models and it is working great. So I am looking for something similar to Parameters.jl where I can easily update the arrays with their new values.

Tell me if it is confusing. I am just looking for the best practices for dealing with lots of preallocated arrays.

Thanks.

8 posts - 5 participants