def worker(fig, ax, hash): with shelve.open("benchmark_results") as results: run(results, comments, hash, True) benchmarks = get_benchmarks(results) for name in benchmarks: xy = benchmarks[name] x, y = np.transpose(xy) for axi in ax.flatten(): for artist in axi.get_children(): if isinstance(artist, lines.Line2D) and artist.get_label() == name: artist.set_xdata(x) artist.set_ydata(y) fig.canvas.draw()
print(args) # Asserting if detype is turned on when parameter fold is turned on: if (args.parameters_fold == 1): assert (args.de_type == 1) if args.version: print("Version 0.9") # If run tests enabled: if (args.run_tests != 0): rt.run_tests(args) # If run benchmarks enabled: elif (args.run_benchmarks != 0): rb.run(args) else: # If detype is set to 1, then we detype: if (args.de_type == 1): dt.detype(args.d, args.p, args.dd_out, args.dp_out) # after generating detyped files, we use them are source: args.d = args.dd_out args.p = args.dp_out # If not extracting plan, we dont test by default: if (args.run < 2): args.testing = 0 # --------------------------------------- Timing the encoding ---------------------------------------- start_encoding_time = time.perf_counter()
def run_benchmarks(nb_particles_short, time_sequential_bench): def create_command(command_template, nb_particles_short, t_end, nb_threads=1): if nb_threads == 1: threads = "serial" else: threads = "threads" return command_template.format( nb_particles_short=nb_particles_short, t_end=t_end, nb_threads=nb_threads, threads=threads, ) print("First run to evaluate t_end for time_sequential_bench") command = create_command(command_template, nb_particles_short, 0.002) run(command, working_dir) if nb_particles_short == "1k": t_end = 2 elif nb_particles_short == "2k": t_end = 0.5 elif nb_particles_short == "16k": t_end = 0.05 else: raise ValueError command = create_command(command_template, nb_particles_short, t_end) t_perf_start = perf_counter() run(command, working_dir) elapsed_time = perf_counter() - t_perf_start print(f"elapsed time: {elapsed_time:.3f} s") t_end = t_end * time_sequential_bench / elapsed_time print(f"We'll run the benchmarks with t_end = {t_end}") timestamp_before = time() time_as_str = get_time_as_str() lines = [] index_run = 0 nb_loops = 2 for i_loop in range(nb_loops): print(f"--- Running all benchmarks ({i_loop+1}/{nb_loops}) ---") for nb_threads in nb_threads_list: # warmup for _ in range(1): command = create_command(command_template, nb_particles_short, 0.004, nb_threads) run(command, working_dir) command = create_command(command_template, nb_particles_short, t_end, nb_threads) sleep(2) t_perf_start = perf_counter() timestamp_start = time() sleep(t_sleep_before) elapsed_time = perf_counter() - t_perf_start timestamp_end = time() sleep(2) lines.append([ "sleep(t_sleep_before)", 1, "None", index_run, timestamp_start, timestamp_end, elapsed_time, ]) t_perf_start = perf_counter() timestamp_start = time() run(command, working_dir) elapsed_time = perf_counter() - t_perf_start timestamp_end = time() print(f"elapsed time: {elapsed_time:.3f} s") sleep(2) lines.append([ f"nbabel5_threads.jl", nb_threads, "julia", index_run, timestamp_start, timestamp_end, elapsed_time, ]) index_run += 1 columns = ( "implementation nb_threads language index timestamp_start timestamp_end elapsed_time" ).split() df = pd.DataFrame( lines, columns=columns, ) df.sort_values("nb_threads", inplace=True) elapsed_serial = df[(df.language == "julia") & (df.nb_threads == 1)]["elapsed_time"].min() df["ratio_elapsed"] = df["elapsed_time"] / elapsed_serial print(df[df.language == "julia"]) node = platform.node() path_dir_result = path_base_repo / "power/tmp" path_dir_result.mkdir(exist_ok=True) path_result = ( path_dir_result / f"parallel_julia_{nb_particles_short}_{node}_{time_as_str}.csv") df.to_csv(path_result) if "grid5000" not in node: return from getwatt import getwatt path_result = path_result.with_suffix(".h5") timestamp_end = time() node_shortname = node.split(".")[0] with h5py.File(str(path_result), "w") as file: file.attrs["t_end"] = t_end file.attrs["node"] = node file.attrs["node_shortname"] = node_shortname file.attrs["nb_particles_short"] = nb_particles_short file.attrs["time_sequential_bench"] = time_sequential_bench file.attrs["t_sleep_before"] = t_sleep_before file.attrs["nb_cpus"] = nb_cpus file.attrs["timestamp_before"] = timestamp_before file.attrs["timestamp_end"] = timestamp_end conso = np.array(getwatt(node_shortname, timestamp_before, timestamp_end)) times = conso[:, 0] watts = conso[:, 1] with h5py.File(str(path_result), "a") as file: file.create_dataset("times", data=times, compression="gzip", compression_opts=9) file.create_dataset("watts", data=watts, compression="gzip", compression_opts=9) print(f"File {path_result} saved")