Accelerate MPI with GPUs

Accelerate MPI with GPUs

You can find this application in the demos folder of your Jupyter notebook environment.

    • athinput.kh
    • plot_output_slice.py
    • plot_slice.py
    • accl_mpi_with_gpus.ipynb
  • Many scientific libraries are being modernized or created to take advantage of GPU acceleration. When the code is designed effectively, this code runs much faster with GPUs than it can with CPUs alone, even large multicore CPUs. For many applications, using GPUs is more cost effective than using large multicore CPUs. So, if you run GPU-optimized code on GPU-accelerated hardwared, you can complete calculations faster, saving time and money .

    Camber’s platform can run codes using on-demand GPU instances. This tutorial uses the Athena engine to run Athenak, a code that has been written to obtain high performance with GPUs. Here, simulate the Kelvin-Helmholtz instability in 2D and visualize the results.

    Build your GPU-run Athena engine

    The first step is to set up the Athena instance. Note the with_gpu flag when initializing the engine.

    from camber.athena import AthenaEngine
    !git clone --recursive https://github.com/IAS-Astrophysics/athenak.git
    # initialize a single Athena Engine with gpu acceleration
    engine = AthenaEngine(engine_size='XSMALL',with_gpu=True,num_engines=1)

    Note that this engine uses the XSMALL engine size. You can increase this size to run on a GPU cluster. For details, refer to Engine Attributes.

    Now use the build method to create an Athena executable that runs the Kelvin-Helmholtz problem. You might need to wait for the GPU instance to be assigned. You can check if the status is pending with engine history attribute.

    # Build AthenaK to run the Kelvin-Helmholtz problem by selecting the "kh" problem generator
    engine.build(problem_generator="kh")
    # Check the status of jobs run with this engine
    engine.history

    Once the build finishes, you can run the job with your input file:

    # Now use the Athena Engine to run a job with "kh.athinput" input file
    engine.run(input_file="kh.athinput")

    Read data from cloud storage and process for visualization

    # import a custom script for reading and plotting the AthenaK outputs, placing images in the output_images directory
    from plot_output_slice import plot_output
    !mkdir output_images 
    plot_output()
    ### Visualize Data
    from IPython.display import Video
    Video("density.mov", width=800, height=800)