Given the computationally intensive nature of the counting of semirings, the package provides a means of parallelisation for counting functions (i.e. those of the form Nr<Structure>, see NrSemirings (2.1-2)).
This works using a bash script and a Python script. The bash script handles the orchestration of the process, while the Python script is responsible for even distribution of workload across cores. Naturally, the user must have a Python3 interpreter installed on their system for this to work.
Currently, there is no support for parallelisation of the enumeration functions (i.e. those of the form All<Structure>, see AllSemirings (2.1-1)).
To use the parallelisation, you must first ensure that both semirings/parallel.sh and semirings/parallel/distribute.py are executable. This can be done by running the following commands in the terminal, inside the pkg/semirings directory:
chmod +x parallel.sh chmod +x parallel/distribute.py
In any examples in the remainder of the chapter, we assume the user is in the pkg/semirings directory when running commands. This is not strictly necessary, but the user should take care to use the correct filepath when running the parallel.sh script.
An example of how to use the parallelisation is as follows:
SEMIRINGS_CORES=7 ./parallel.sh 'NrAiSemirings(4)'
This will run the command NrAiSemirings(4) in parallel across 7 cores, distributing the workload evenly. The output will be printed to the terminal and while the process is running, temporary log files will be created in the parallel/logs directory, where the user can check on the progress of an individual core. These files, along with any other files created by the script, will be deleted upon successful completion of the script.
A typical output for the above command might look like the following:
Using 7 cores Establishing how to distribute the workload... Distributing 188 items across 7 cores... Running processes concurrently, logs available @ semirings/parallel/logs ---------------------------------------------------------------------- RESULT for NrAiSemirings(4) Total = 866 ----------------------------------------------------------------------
If SEMIRINGS_CORES is not specified, the script will default to using all available cores. Alternatively, if the user intends on regularly using n cores for some n, they can set the SEMIRINGS_CORES environment variable by running the following command in the terminal:
export SEMIRINGS_CORES=n
This will set the number of cores to be used by the script to n for the current terminal session. The user can add this line to their shell configuration file (e.g., .bashrc or .zshrc) to make this change persist across terminal sessions.
It is also possible to run multiple commands in parallel by specifying them as a list in the command line. For example:
SEMIRINGS_CORES=2 ./parallel.sh 'NrAiSemirings(4)' 'NrAiSemirings(5, true)'
This will first run NrAiSemirings(4) across 2 cores, and then upon completion, it will run NrAiSemirings(5, true) across 2 cores.
generated by GAPDoc2HTML