def run_problem(real, imag, max_iter, num_steps, num_nodes, criteria, task, num_tasks, n_procs, starttime): _width = len(str(num_tasks)) _percent = float(task) / float(num_tasks) * 100 _diff_time = time.time() - starttime _time_epsilon = 0.1 if task > n_procs \ and ((_diff_time > 8.0 and ((_diff_time % 10.0) < _time_epsilon) or ((10.0 - (_diff_time % 10.0)) < _time_epsilon)) or (num_tasks % 2 == 0 and _percent % 4 == 0) or (num_tasks % 2 != 0 and _percent % 4 == 0)): print("[ {:6.2f}%] Starting task {:{width}d} of {:{width}d}: \\lambda = {: .3f}{:+.3f}i" .format(_percent, task, num_tasks, real, imag, width=_width)) problem = LambdaU(lmbda=complex(real, imag)) check = ThresholdCheck(min_threshold=1e-14, max_threshold=max_iter, conditions=('residual', 'iterations')) comm = ForwardSendingMessaging() solver = ParallelSdc(communicator=comm) comm.link_solvers(previous=comm, next=comm) comm.write_buffer(value=problem.initial_value, time_point=problem.time_start) solver.init(integrator=SdcIntegrator, problem=problem, threshold=check, num_time_steps=num_steps, num_nodes=num_nodes) try: solution = solver.run(SemiImplicitSdcCore, dt=(problem.time_end - problem.time_start)) return int(solution[-1].used_iterations) except RuntimeError: return max_iter + 1
def solve_parallel(prob, _core): thresh = ThresholdCheck(max_threshold=25, min_threshold=1e-7, conditions=('error', 'solution reduction', 'error reduction', 'residual', 'iterations')) comm = ForwardSendingMessaging() solver = ParallelSdc(communicator=comm) comm.link_solvers(previous=comm, next=comm) comm.write_buffer(value=prob.initial_value, time_point=prob.time_start) solver.init(integrator=SdcIntegrator, threshold=thresh, problem=prob, num_time_steps=1, num_nodes=3) sol = solver.run(core=_core, dt=0.5) print(sol)
def _run_sdc_with_problem(problem, core, num_time_steps, dt, num_nodes, max_iter, precision): thresh = ThresholdCheck(max_threshold=max_iter + 1, conditions=('error', 'residual', 'solution reduction', 'error reduction', 'iterations'), min_threshold=1e-7) _comm = ForwardSendingMessaging() _sdc = ParallelSdc(communicator=_comm) _comm.link_solvers(previous=_comm, next=_comm) _comm.write_buffer(value=problem.initial_value, time_point=problem.time_start) _sdc.init(integrator=SdcIntegrator, threshold=thresh, problem=problem, num_time_steps=num_time_steps, num_nodes=num_nodes) _solution = _sdc.run(core, dt=dt) # for _node_index in range(0, len(_solution.solution(-1))): # print("Node {}: {} <-> {}".format(_node_index, _solution.solution(-1)[_node_index].value, problem.exact(_solution.solution(-1)[_node_index].time_point))) # assert_numpy_array_almost_equal(_solution.solution(-1)[_node_index].value, # problem.exact(_solution.solution(-1)[_node_index].time_point), # places=2) assert_true(len(frozenset(thresh.has_reached()).intersection(frozenset(('error', 'solution reduction', 'error reduction', 'residual')))) > 0, "Termination criteria should be 'error' or 'residual'.") assert_not_in('iterations', thresh.has_reached(), "Maximum Number of iterations should not be reached.")