The main modification of link_cell_pairs consists of removing the condition ll mxlist in the loop over jj (the inner loop over atoms). This is shown below in Algorithm 1. It should be noted that it is not possible to do the same for the If conditon dependent on rsq as rsq depends on jj.

The main point is to divide the loop over into two parts : one part when, for every in , ; the second part for all the other cases. For the former, the condition above can be written as and . As and testing whether _ _ is true outside the loop allows us to evaluate whether the ll mxlist condition need be tested inside the loop. If this new condition is true the ll mxlist condition in the original code can never be true, and so in the the loop over it is sufficient just to evaluate the If condition over . On the other hand if it is not true the original version of the loop over must be executed, with both the conditions over and evaluated.

This optimisation should improve the performance of the code whenever ll mxlist for every jj in , which is the common case; if this condition is not true it actually indicates a run time error for the code. A comparison of the two algorithms can be seen below.

Valène Pellissier 2011-08-24