luca-scr / GA

An R package for optimization using genetic algorithms
http://luca-scr.github.io/GA/
91 stars 29 forks source link

Is the default parallel execution prescheduled? #42

Open mosscoder opened 4 years ago

mosscoder commented 4 years ago

Greetings, I appreciate the work you have contributed to this package. The execution time of my fitness function varies greatly depending on the input values, and for parallel execution I think it would make the most sense to not preschedule the work done by my cluster. Is ga() prescheduled by default? If so, how would I go about forking work in a unscheduled way?

My understanding is that the preschedule=FALSE argument is supplied to foreach, but I'm not sure how to pass this to ga().

mosscoder commented 4 years ago

I'm guessing this would need to be added here: https://github.com/luca-scr/GA/blob/c87a2a1d7f85affc470aae0380085a6e9eff2644/R/ga.R#L235-L242

The foreach call could be change as follows: foreach(i. = seq_len(popSize), .combine = "c", .options.multicore = list(preschedule = FALSE)

luca-scr commented 4 years ago

What about if a user want to set preschedule = TRUE (which I think is the default, see help("mclapply", package = "parallel") ? And what happens if a different backend is used? And if a cluster is set up by a user and then passed to the parallel argument of ga() function call? Your proposal should work but I'm worrying about backwards compatibility.

mosscoder commented 4 years ago

Well here is one possible implementation here, simply adding a preschedule argument to ga(), defaulted to TRUE:

https://github.com/mosscoder/GA/blob/4d2853f2ecb0de78fed035d77b5c61f49d28e033/R/ga.R#L7-L35

https://github.com/mosscoder/GA/blob/4d2853f2ecb0de78fed035d77b5c61f49d28e033/R/ga.R#L237-L243