Skip to content

[New Feature]: Improve computation efficiency #69

Description

@thomasarsouze

Describe your feature request

spatialBehaviour and temporalBehaviour are kind of slow to run. For exemple, it takes 37.5s on my computer (mac osx 2020, 2 GHz Intel Core i5 four cores) to run the spatialBehaviour function for only 7 storms:

ds <- defStormsDataset()
s <- defStormsList(ds)
s <- defStormsList(ds, loi="New Caledonia")
=== Storms processing ... ===

-> Making buffer: Done
-> Searching storms from 2015 to 2021 ...
   -> Identifying Storms: 9 potential candidates...
-> Gathering storm(s) ... 
  |===================================================================================================================================| 100%

=== DONE with run time 1.182287 sec ===

SUMMARY:
(*) LOI: New Caledonia 
(*) Buffer size: 300 km
(*) Remove Tropical Depressions (< 18 m/s in sshs): yes
(*) Number of storms: 7 
        Name - Tropical season - SSHS - Number of observation within buffer:
        PAM - 2015 - 5 - 5 
        SOLO - 2015 - 0 - 15 
        ULA - 2016 - 4 - 9 
        UESI - 2020 - 1 - 16 
        GRETEL - 2020 - 1 - 11 
        LUCAS - 2021 - 1 - 16 
        NIRAN - 2021 - 5 - 10 

msw <- spatialBehaviour(s)

We want the code to be faster.

Describe the solution you'd like

Three things must be considered to improve efficency when doing the computation of storms behaviour:

  • analyze bottlenecks and find where spatialBehaviour spends most of its time
  • implement the computing functions in C++ using Rcpp library
  • implement parallel looping

  1. We must use a profiling library to analyse the time spent in different functions:
library(profvis)
profvis(spatialBehaviour(s))

First analysis with the exemple above shows that :

  • overall time in this function is 35170ms
  • computational time in spatialBehaviour itself is 5800ms
  • all the remaining time is spent in .External functions, which are tipicaly sf functions.

This means that we should consider means to lower the number of calls to sf functions.

  1. Code in Rcpp the computing functions, including:
  • computeAsymmetry
  • willoughby
  • holland
  • boose
  • computeDirectionBoose
  • computeDirection
    although as stated above, this is limited to a small fraction of the total computational time
  1. Test the parallel-looping when available:
  • auto detect number of cores
  • implement parallel-looping (keeping order) using foreach library when relevent (and possible)

Describe alternatives you've considered

  • reorganize code and sf functions calls
  • code computing functions in Rcpp
  • test parallel-looping using foreach library

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions