This paper describes a numerical method to optimize elastic bodies featuring a locally periodic microscopic pattern. A new idea, of optimizing the periodicity cell itself, is considered. In previously published works, the authors have found that optimizing the shape and topology of the model hole gives a limited flexibility to the microstructure for adapting to the macroscopic loads. In the present study the periodicity cell varies during the optimization process, thus allowing the microstructure to adapt freely to the given loads. Our approach makes the link between the microscopic level and the macroscopic one. Two-dimensional linearly elastic bodies are considered, however the same techniques can be applied to three-dimensional bodies. Homogenization theory is used to describe the macroscopic (effective) elastic properties of the body. Numerical examples are presented, in which a cantilever is optimized for different load cases, one of them being multi-load. The problem is numerically heavy, since the optimization of the macroscopic problem is performed by optimizing in simultaneous hundreds or even thousands of periodic structures, each one using its own finite element mesh on the periodicity cell. Parallel computation is used in order to alleviate the computational burden.