@hpx.create_action() def calculate(num_gil): for i in range(num_gil): giltest.calculate(262144 // num_gil) # 262144 is 2^18 return hpx.SUCCESS @hpx.create_action() def main(): time = np.zeros((18, )) for j in range(18): num_gil = 2**j start = hpx.time_now() and_lco = hpx.And(num_action) for i in range(num_action): calculate(hpx.HERE(), num_gil, rsync_lco=and_lco) and_lco.wait() current_time = hpx.time_elapsed_ms(start) print(current_time) time[j] = current_time print(time) time.dump("time.bin") hpx.exit() if __name__ == '__main__': hpx.init(sys.argv) hpx.run(main) hpx.finalize()
(2 * abs(pos - node['moments']['xcom'])**3)) def node_compute_direct(particles, pos): a = -particles['mass'] / np.abs(particles['pos'] - pos) return np.sum(a) if __name__ == '__main__': try: hpx.init(sys.argv) except HPXError: # TODO pass if len(sys.argv) != 5: print_usage() hpx.finalize() sys.exit(0) # convert arguments to numerical values n_parts, n_partition, theta_c, domain_size = sys.argv[1:] n_parts = int(n_parts) n_partition = int(n_partition) theta_c = float(theta_c) domain_size = float(domain_size) hpx.run(main, n_parts, n_partition, theta_c, domain_size) hpx.finalize()
num_node = hpx.get_num_ranks() print("program runs on {0} nodes".format(num_node)) step_size = (high - low) / total_cells cell_per_node = total_cells // num_node result_lco = hpx.Reduce(num_node, (1, ), np.dtype(float), result_init, result_op) for i in range(num_node): calculate_integral(hpx.THERE(i), low + i * step_size * cell_per_node, step_size, cell_per_node, result_lco) print(result_lco.get()) print(fint(high) - fint(low)) hpx.exit() @hpx.create_action() def calculate_integral(start, step_size, cell_per_node, result_lco): result = 0 for i in range(cell_per_node): s1 = f(start + i * step_size) s2 = f(start + (i + 1) * step_size) result += (s1 + s2) * step_size / 2 result_lco.set(np.array([result])) return hpx.SUCCESS if __name__ == '__main__': hpx.init(sys.argv) hpx.run(main_action) hpx.finalize()
import hpx import giltest import sys @hpx.create_action() def calculate(num): giltest.calculate(num) return hpx.SUCCESS @hpx.create_action() def main(num_action): start = hpx.time_now() and_lco = hpx.And(num_action) for i in range(num_action): calculate( hpx.HERE(), 5765760 // num_action, rsync_lco=and_lco) # 5040 is lcm(2,3,4,5,6,7,8,9,10,12,14,15,16) and_lco.wait() print(hpx.time_elapsed_ms(start)) hpx.exit() if __name__ == '__main__': hpx.init(sys.argv) hpx.run(main, int(sys.argv[1])) hpx.finalize()
rtv_array = np.arange(30).reshape((5, 6)) hpx.thread_continue('array', rtv_array) return hpx.SUCCESS @hpx.create_action() def call_cc(): hpx.call_cc(set_future, hpx.HERE()) return hpx.SUCCESS @hpx.create_action() def set_future(): rtarray = np.arange(12).reshape((3, 4)) hpx.thread_continue('array', rtarray) return hpx.SUCCESS @hpx.create_action() def set_funture_2(future): starray = np.arange(12).reshape((3, 4)) future.set(starray) return hpx.SUCCESS if __name__ == '__main__': hpx.init() rtv = hpx.run(main, shape=(2, 3), dtype=np.dtype(int)) assert np.array_equal(rtv, np.arange(6).reshape((2, 3))) hpx.finalize()