Configure task communication using an MPI library

This document explains how to configure a Batch job with tightly coupled tasks that communicate with each other across different VMs by using a Message Passing Interface (MPI) library.

For Batch jobs, coupling describes the interdependency tasks; this influences how you configure the number of tasks that can run in parallel (instead of sequentially) using a job's parallelism field. Tasks can be described using the following types of coupling:

  • Loosely coupled tasks: tasks that can run independently.
  • Tightly coupled tasks: tasks that are dependent on each other to run.

Optionally, you can create a job that uses an MPI library to let tightly coupled tasks communicate with each other across different VM instances. A common use case for MPI is tightly coupled high-performance computing (HPC) workloads.

Before you begin

  1. If you haven't used Batch before, review Get started with Batch and enable Batch by completing the prerequisites for projects and users.
  2. To get the permissions that you need to create a job, ask your administrator to grant you the following IAM roles:

    For more information about granting roles, see Manage access to projects, folders, and organizations.

    You might also be able to get the required permissions through custom roles or other predefined roles.

  3. If you specify the network for this job, make sure the network has a firewall rule that allows connections between the job's VMs. Learn how to Configure VPC firewall rules for common use cases.

Create and run a job that uses MPI for tightly coupled tasks

This section provides examples for how to create a job that can use MPI. Notably, the example job has 3 runnables:

  • The first runnable is a script that prepares the job for MPI by disabling simultaneous multithreading and installing Intel MPI.
  • The second runnable is an empty barrier runnable (formatted as { "barrier": {} }), which ensures that all tasks finish setting up MPI before continuing to future runnables.
  • The third runnable (and any subsequent runnables) is available for the job's workload.

You can create a job that uses MPI for tightly coupled tasks using the gcloud CLI or Batch API.

gcloud

To create a script job that uses MPI for tightly coupled tasks by using the gcloud CLI, do the following:

  1. Create a JSON configuration file with the following contents:

    {
        "taskGroups": [
            {
                "taskSpec": {
                    "runnables": [
                        {
                            "script": {
                                "text": "google_mpi_tuning --nosmt; google_install_mpi --intel_mpi;"
                            }
                        },
                        { "barrier": {} },
                        {
                            "script": {
                                SCRIPT
                            }
                        }
                    ]
                },
                "taskCount": TASK_COUNT,
                "taskCountPerNode": TASK_COUNT_PER_NODE,
                "requireHostsFile": REQUIRE_HOSTS_FILE,