DassHydro / smash

An open source, Python library interfacing the Fortran Spatially distributed Modelling and ASsimilation for Hydrology platform.
https://smash.recover.inrae.fr/
GNU General Public License v3.0
12 stars 6 forks source link

BUG: fill control vector with distributed mapping #265

Closed inoelloc closed 2 months ago

inoelloc commented 2 months ago

The filling of the control vector with distributed mapping is very slow. The reason is that in the filling loop, the nbd variable, which is an array of size n, is completly overwrited at each iteration instead of assigning a single value. This bug has not affected simulations so far because the correct value is assigned, but in the case of distributed mapping over very large domains, the time taken to fill the control vector becomes excessive. O(n²) instead of O(n)

do i = 1, setup%nrrp

            if (options%optimize%rr_parameters(i) .eq. 0) cycle

            do col = 1, mesh%ncol

                do row = 1, mesh%nrow

                    if (mesh%active_cell(row, col) .eq. 0) cycle

                    j = j + 1

                    parameters%control%x(j) = parameters%rr_parameters%values(row, col, i)
                    parameters%control%l(j) = options%optimize%l_rr_parameters(i)
                    parameters%control%u(j) = options%optimize%u_rr_parameters(i)
                    parameters%control%nbd = 2
                    write (name, '(a,i0,a,i0)') trim(parameters%rr_parameters%keys(i)), row, "-", col
                    parameters%control%name(j) = name

                end do

            end do

        end do

The solution is to affect the value for the corresponding indice such that:

parameters%control%nbd(j) = 2