Message passing for task redistribution on sparse graphs