You may try to create clusters, using the write method (writes the cluster id directly as a property in memory), or any kind of community like that before, and run an algorithm for each of these ...