Computational optimization of diffractive elements is often limited by a large number of design parameters. Adjoint method allows the gradient of target function respect to all design variables to be calculated with only two electromagnetic simulations. We show that detail results for optimized two-dimensional fan-out gratings.