Modular robots are usually composed of multiple blocks with uniform docking interfaces that can be transformed into different configurations. It is a significant challenge to recognize modular robot configurations composed of hundreds of modules. Given a new configuration, it is important to match it to an existing configuration and, if true, map each module to the module in this matching configuration when applying many modular robot control schemes. An efficient algorithm is presented to address this matching and mapping problem by making use of distributed information from each module and new structure to design the configuration library. The cluster is discovered and the root module is determined first. Then the matching and mapping problem is solved simultaneously in polynomial time. The algorithm is demonstrated on real modular robots and shown to be efficient to solve this configuration recognition problem.