The optimal resource allocation in the large-scale intelligent device-to-device (D2D) communication system is of great importance for improving system spectrum efficiency and ensuring communication quality. In this study, the D2D resource allocation is modelled as an ultrahigh-dimensional optimization (UHDO) problem with thousands of binary dimensionalities. Then, for efficiently optimizing this UHDO problem, the coupling relationships among those dimensionalities are comprehensively analysed, and several efficient variable-grouping strategies are developed, i.e., cellular user grouping (CU-grouping), D2D pair grouping (DP-grouping), and random grouping (R-grouping). In addition, a novel evolutionary algorithm called the cooperatively coevolving particle swarm optimization with variable-grouping (VGCC-PSO) is developed, in which a novel mutation operation is introduced for ensuring fast satisfaction of constraints. Finally, the proposed UHDO-based allocation model and VGCC-PSO algorithm as well as the grouping and mutation strategies are verified by a comprehensive set of case studies. Simulation results show that the developed VGCC-PSO algorithm performs the best in optimizing the UHDO model with up to 6000 dimensionalities. According to our study, the proposed methodology can effectively overcome the “curse of dimensionality” and optimally allocate the resources with high accuracy and robustness.