# Fast Overlap Detection between Hard-Core Colloidal Cuboids and Spheres. The OCSI Algorithm
## 2 Algorithms
Moreover, because colloids can be especially dense systems, one random configuration might generate more than a single collision. Consequently, it is reasonable to assume that, within a single Monte Carlo simulation, a \begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline  & \multicolumn{8}{c}{**Intel® C Compiler**} \\ \cline{2-9} \(R^{*}\) & \multicolumn{4}{c}{_SSE_} & \multicolumn{4}{c}{_AVX_} \\ \cline{2-9}  & QRI & QRF & OCSI & SSE-intr & QRI & QRF & OCSI & SSE-intr \\ \hline
0.05 & 24 & 22 & 11 & 12 & 25 & 21 & 10 & 12 \\
0.50 & 38 & 28 & 11 & 12 & 39 & 27 & 10 & 12 \\
5.00 & 54 & 39 & 11 & 12 & 55 & 38 & 10 & 12 \\ \hline \hline \multicolumn{9}{c}{**GNU C++ Compiler**} \\ \cline{2-9} \(R^{*}\) & \multicolumn{4}{c}{_SSE_} & \multicolumn{4}{c}{_AVX_} \\ \cline{2-9}  & QRI & QRF & OCSI & SSE-intr & QRI & QRF & OCSI & SSE-intr \\ \hline
0.05 & 23 & 24 & 13 & 11 & 23 & 22 & 12 & 11 \\
0.50 & 37 & 30 & 13 & 11 & 37 & 28 & 12 & 11 \\
5.00 & 53 & 41 & 13 & 11 & 53 & 38 & 12 & 11 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Average run-times of the C/C++ version of algorithms for collision detection between one cuboid of \(1\leq L^{*}\leq 20\) and \(1\leq W^{*}\leq 20\) and one sphere of radius \(R^{*}\) over \(2\times 10^{6}\) configurations with 40% of acceptance ratio. Results, reported in ms, are obtained compiling the benchmark program using Intel® C Compiler and GNU C++ Compiler, enabling the generation of SSE and AVX instructions. The standard deviations of all the run-times are <0.5 ms. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline  & \multicolumn{8}{c}{**Intel® Fortran Compiler**} \\ \cline{2-9} \(R^{*}\) & \multicolumn{4}{c}{_SSE_} & \multicolumn{4}{c}{_AVX_} \\ \cline{2-9}  & QRI & QRF & OCSI & QRI & QRF & OCSI \\ \hline
0.05 & 22 & 21 & 13 & 22 & 22 & 13 \\
0.50 & 36 & 27 & 13 & 36 & 28 & 13 \\
5.00 & 53 & 38 & 13 & 53 & 40 & 13 \\ \hline \hline \multicolumn{9}{c}{**GNU Fortran Compiler**} \\ \cline{2-9} \(R^{*}\) & \multicolumn{4}{c}{_SSE_} & \multicolumn{4}{c}{_AVX_} \\ \cline{2-9}  & QRI & QRF & OCSI & QRI & QRF & OCSI \\ \hline
0.05 & 23 & 21 & 17 & 22 & 21 & 18 \\
0.50 & 38 & 27 & 17 & 36 & 27 & 18 \\
5.00 & 56 & 37 & 17 & 53 & 36 & 18 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Average run-times of the F90 version of algorithms for collision detection between one cuboid of \(1\leq L^{*}\leq 20\) and \(1\leq W^{*}\leq 20\) and one sphere of radius \(R^{*}\) over \(2\times 10^{6}\) configurations with 40% of acceptance ratio. Results, reported in ms, are obtained compiling the benchmark program using Intel® Compiler and GNU Fortran Compiler, enabling the generation of SSE and AVX instructions. The standard deviations of all the run-times are <0.5 ms.

collision-detection algorithm might be called between \(10^{3}\) and \(10^{5}\) times the configurations explored here. This would produce a difference of seconds between OCSI and SSE-intr, which is still not especially relevant. The main advantage of using OCSI is that it is based on automatic vectorization and employs OpenMP libraries to be parallelized, making it a very user-friendly algorithm. Since SSE-intr uses intrinsic functions that are specific for SSE, this version of the algorithm for cuboid-sphere collision detection is limited only to that instruction set. Moreover, Intel(r) intrinsic functions are available only in C and cannot be used in Fortran, unless we compile a mixed C/Fortran program. In contrast, OCSI is based on automatic vectorization by the compiler, guided using OpenMP pragmas and directives. In this way, the algorithm can be extended to different instruction sets without changing the source code, simply specifying the instruction set during compilation. It can also implement vectorization in Fortran and extend its use to 64-bit floating point arithmetic, which is commonly used in molecular modelling.