Implementation of multi grid algorithm