Motivated by the problem of designing robust composite pulses for Bloch equations in the presence of natural perturbations, we study an abstract optimal ensemble control problem in a probabilistic setting with a general nonlinear performance criterion. The model under study addresses meanfield dynamics described by a linear continuity equation in the space of probability measures. For the resulting optimization problem, we derive an exact representation of the increment of the cost functional in terms of the flow of the driving vector field. Relying on the exact increment formula, a descent method is designed that is free of any internal line search. The numerical method is applied to solve new control problems for distributed ensembles of Bloch equations. *The authors acknowledge the financial support of the Foundation for Science and Technology (FCT, Portugal) in the framework of the Associated Laboratory "Advanced Production and Intelligent Systems" (AL ARISE, ref. LA/P/0112/2020), R&D Unit SYSTEC (base UIDB/00147/2020 and programmatic UIDP/00147/2020 funds), and projects SNAP (ref. NORTE-01-0145-FEDER-000085) and MLDLCOV (ref. DSAIPA/CS/0086/2020).