This repository contains seven methods to accelerate a serial Python implementation of the Lebwohl-Lasher model; simulation of liquid crystal behaviour. Each method implements a different optimisation strategy with combined approaches also explored.
A basic serial implementation, provided by Dr. Simon Hanna.
python LebwohlLasher.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG>Uses the Numba just-in-time compiler, converting the script to machine code at compilation time.
python LebwohlLasher_numba.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG>Compiles critical sections (inefficient loops) using Cython.
pip install CythonCC=gcc-15 python setup_LebwohlLasher_cython.py build_ext -fipython run_LebwohlLasher_cython.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG>Vectorised implementation using NumPy arrays for efficient operations.
python LebwohlLasher_numpy.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG>Parallelised using OpenMP within Cython.
brew install llvm
brew install libompCC=gcc-15 python setup_LebwohlLasher_openmp.py build_ext -fipython LebwohlLasher_openmp.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG> <THREADS>Distributed memory parallelisation using mpi4py.
brew install open-mpipip install mpi4pympiexec -n <TASK_COUNT> python LebwohlLasher_mpi4py.py <ITERATIONS> <SIZE> <TEMPERATURE> <PLOTFLAG>Implementations combining multiple acceleration approaches:
LebwohlLasher_numpyxmpi4py.py— NumPy + MPILebwohlLasher_numpyxcython.py— NumPy + Cython
Usage mirrors the respective base methods.
| Argument | Description |
|---|---|
ITERATIONS |
The number of MC steps for a given simulation |
SIZE |
Lattice size, integer input for a side length |
TEMPERATURE |
Reduced temperature, T*, for a simulation |
PLOTFLAG |
0 for no plot, 1 for energy plot and 2 for angle plot |
THREADS |
(OpenMP only) Number of threads |
TASK_COUNT |
(MPI only) Number of parallel processes - must be >1 |
Data was gathered with bash scripts that ran simulations for multiple input parameters. Data has been processed using the data_processing.ipynb script.
- All implementations assume Python 3.
- Plotting requires
matplotlib. - Task count, for mpi implementations must be 2 or greater, as the master task is not a worker task.