  An algorithm to compute efficiently the first two derivatives of (very) large
multideterminant wavefunctions for quantum Monte Carlo calculations is
presented. The calculation of determinants and their derivatives is performed
using the Sherman-Morrison formula for updating the inverse Slater matrix. An
improved implementation based on the reduction of the number of column
substitutions and on a very efficient implementation of the calculation of the
scalar products involved is presented. It is emphasized that multideterminant
expansions contain in general a large number of identical spin-specific
determinants: for typical configuration interaction-type wavefunctions the
number of unique spin-specific determinants $N_{\rm det}^\sigma$
($\sigma=\uparrow,\downarrow$) with a non-negligible weight in the expansion is
of order ${\cal O}(\sqrt{N_{\rm det}})$. We show that a careful implementation
of the calculation of the $N_{\rm det}$-dependent contributions can make this
step negligible enough so that in practice the algorithm scales as the total
number of unique spin-specific determinants, $\; N_{\rm det}^\uparrow + N_{\rm
det}^\downarrow$, over a wide range of total number of determinants (here,
$N_{\rm det}$ up to about one million), thus greatly reducing the total
computational cost. Finally, a new truncation scheme for the multideterminant
expansion is proposed so that larger expansions can be considered without
increasing the computational time. The algorithm is illustrated with
all-electron Fixed-Node Diffusion Monte Carlo calculations of the total energy
of the chlorine atom. Calculations using a trial wavefunction including about
750 000 determinants with a computational increase of $\sim$ 400 compared to a
single-determinant calculation are shown to be feasible.
