Multi-Threading API Reference

MERA.jl Multi-Threading Performance

Reference for Mera's threading controls. The guide — what is parallel, what to expect, how to choose a thread count — is Multi-Threading.

Threads are set when Julia starts, not from inside a session:

julia -t 8              # or: export JULIA_NUM_THREADS=8

Which functions are threaded, and over what

Every function below accepts max_threads::Int to cap what it uses, defaulting to Threads.nthreads(). The dimension each one parallelises over decides whether more threads help — a single-variable projection stays flat no matter how many you give it.

FunctionParallel over
gethydro, getparticles, getgravity, getrtRAMSES CPU-file chunks
projectionthe variables requested in one call
clumpfindcandidate chunks
export_vtkparticles / cells
convertdata, batch_convert_meracomponents being converted
gas = gethydro(info, max_threads=4)                       # cap the read
projection(gas, [:sd, :T, :vx], :km_s, max_threads=3)     # one task per variable

Diagnostics

Mera.show_threading_infoFunction
show_threading_info()

Display information about Julia threading configuration and recommendations.

Benchmarking

Measure on your own data and storage rather than assuming — reading is usually I/O bound and saturates when the storage does.

Mera.benchmark_projection_hydroFunction
benchmark_projection_hydro(gas_data, thread_counts::Vector{Int}, n_runs::Int=10, output_file::String="") → Dict

Execute comprehensive AMR hydro projection benchmark with robust statistical analysis.

This function serves as the main coordinator for hydro projection performance testing. It performs AMR structure analysis, data quality validation, executes both single-variable and multi-variable projection benchmarks across specified thread counts, and exports results in multiple formats with comprehensive statistical analysis.

Benchmark Methodology

  • Single-Variable Test: Surface density projection (:sd → Msun/pc²)
  • Multi-Variable Test: 10 simultaneous variable projections: vars = [:v, :σ, :σx, :σy, :σz, :vrcylinder, :vϕcylinder, :σrcylinder, :σϕcylinder, :cs]
  • Statistical Robustness: several repetitions per configuration with coefficient of variation
  • Quality Control: Success rate monitoring (>80% threshold for reliable data)
  • Memory Profiling: Peak memory usage and garbage collection analysis

Threading Analysis

Evaluates performance across thread counts with derived metrics:

  • Speedup: Performance improvement vs single-threaded execution
  • Efficiency: Speedup per thread (percentage of ideal scaling)
  • Memory Scaling: Memory usage patterns across thread configurations

Output Files Generated

  • {output_file}.csv: Structured data for spreadsheet analysis and plotting
  • {output_file}.json: Machine-readable structured data for programmatic access
  • {output_file}_summary.txt: Human-readable performance report with insights

Arguments

  • gas_data: HydroDataType object from loaddata() or gethydrodata()
  • thread_counts::Vector{Int}: Thread counts to benchmark [1, 2, 4, 8, 16, ...]
  • n_runs::Int=10: Statistical repetitions per configuration (10 for robust analysis)
  • output_file::String="": Output filename base (auto-generated timestamp if empty)

Returns

Dictionary containing complete benchmark results with keys:

  • n_threads, test_type, mean_time, std_time, speedup, efficiency
  • mean_memory, success_rate, min_time, max_time, n_runs

Example Usage

# Load RAMSES hydro data
gas_data = loaddata(300, "/path/to/ramses/output/", :hydro)

# Run comprehensive benchmark (single + multi-variable)
results = benchmark_projection_hydro(gas_data, [1, 2, 4, 8, 16], 10, "performance_test")

# Results saved as:
# - performance_test.csv (for plotting with plot_results.jl)
# - performance_test.json (for programmatic analysis)  
# - performance_test_summary.txt (human-readable report)

Performance Insights

The benchmark automatically analyzes threading efficiency and provides guidance:

  • Identifies optimal thread counts for your system and data size
  • Detects threading bottlenecks and memory constraints
  • Quantifies single vs multi-variable projection performance differences
  • Provides statistical confidence intervals for all measurements

Integration Workflow

  1. Data Loading: Use Mera's loaddata() for your RAMSES simulation
  2. Benchmarking: Execute this function with desired thread counts
  3. Visualization: Use plot_results.jl to create performance dashboards
  4. Analysis: Review summary.txt for optimization recommendations
Mera.run_reading_benchmarkFunction
run_reading_benchmark(output_number, path)

Time reading one RAMSES output under the current thread configuration and save the result.

Used to produce the parallel RAMSES-reading benchmark in the documentation; run it once per thread setting to build the scaling curve.

Mera.run_merafile_benchmarkFunction
run_merafile_benchmark(path, output, num_repeats=10)

Time repeated reads of a compressed mera/JLD2 file and print the resulting statistics.

Used to produce the Mera-Files reading benchmark in the documentation. It reads the same output num_repeats times, so point it at a small dataset.

Mera.benchmark_mera_ioFunction
benchmark_mera_io(simulation_path::String, output_num::Int; 
                 test_sizes=["32KB", "64KB", "128KB", "256KB"])

Benchmark different I/O configurations to find optimal settings for your specific simulation.

This function tests various buffer sizes with your actual data to determine which configuration gives the best performance on your system.

Arguments

  • simulation_path: Path to your RAMSES simulation directory
  • output_num: Output number to test with
  • test_sizes: Array of buffer sizes to test (as strings)

Returns

  • Dictionary with benchmark results and recommended optimal settings

Example

# Standard benchmark
results = benchmark_mera_io("/path/to/simulation", 300)

# Custom buffer sizes to test
results = benchmark_mera_io("/path/to/simulation", 300, 
                           test_sizes=["64KB", "128KB", "256KB", "512KB"])

# Access results
optimal_buffer = results["optimal_buffer_size"]
performance_gain = results["performance_improvement"]

What it does

  1. Tests each buffer size with your actual simulation data
  2. Measures getinfo() and gethydro() performance
  3. Identifies the optimal buffer size for your system
  4. Automatically applies the best settings
  5. Returns detailed performance comparison
Mera.benchmark_buffer_sizesFunction
benchmark_buffer_sizes(simulation_path::String, output_num::Int; 
                      test_sizes=[32768, 65536, 131072, 262144], verbose=true)

Benchmark different buffer sizes to find the optimal setting for this specific simulation.

I/O tuning

Buffer sizes and caching interact with thread count on a networked or slow filesystem; these are documented with the rest of the I/O controls in the Mera-Files API.


Every docstring in the package is also on the Complete API Reference.