Hi Collin,
Although graph4lg is an R package, its graphab_x()
functions are essentially wrappers calling the Java language Graphab software program, after preparing the Java command lines corresponding with the arguments you provide. More specifically, it calls Graphab 2.8 downloaded on your machine by the get_graphab()
function at the first use and located in the repository whose path is given by rappdirs::user_data_dir()
.
For this reason, usual ways to parallelize R functions are ineffective (for instance using foreach
loops).
There is however a way to parallelize the computations performed by these functions on several cores. It consists in asking Java to do it.
The Graphab command line functionalities make it possible to include a -proc n
argument, where n is the number of processors/cores on which the computation is parallelized.
Therefore, it is possible to add this argument to the command line provided by R. I have modified the graphab_metric()
function so that this is possible.
You can now find the graphab_metric_para()
function on the development version of graph4lg hosted on gitlab: https://gitlab.com/psavary3/graph4lg/-/blob/master/R/graphab_metric_para.R?ref_type=heads
You can either download the whole package from gitlab, or just load this function manually. When downloading the package, you might need to call the function with graph4lg:::graphab_metric_para()
given that I parametrized it as an "internal" function.
The "proc
" argument will require the number of cores you want to run the computation on (default = 1).
Prior to using it, you can check how many cores are available on your machine using: parallel::detectCores()
It is recommended to use at most n - 1 cores, n being the total number of cores on your machine.
I admit that this is a quick fix and that ideally, all the Graphab functions of graph4lg should have this argument built in. That's for another version!
Thanks for your interest and for reaching out
Feel free to tell if that doesn't work for you
Best,
Paul