Get started with EFA and MPI
This tutorial helps you to launch an EFA and MPI-enabled instance cluster for HPC workloads. In this tutorial, you will perform the following steps:
Contents
- Step 1: Prepare an EFA-enabled security group
- Step 2: Launch a temporary instance
- Step 3: Install the EFA software
- Step 4: Disable ptrace protection
- Step 5: (Optional) Install Intel MPI
- Step 6: Install your HPC application
- Step 7: Create an EFA-enabled AMI
- Step 8: Launch EFA-enabled instances into a cluster placement group
- Step 9: Terminate the temporary instance
- Step 10: Enable passwordless SSH
Step 1: Prepare an EFA-enabled security group
An EFA requires a security group that allows all inbound and outbound traffic to and from the security group itself. The following procedure allows all inbound and outbound traffic for testing purposes only. For other scenarios, see Security group rules for different use cases.
To create an EFA-enabled security group
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
. -
In the navigation pane, choose Security Groups and then choose Create security group.
-
In the Create security group window, do the following:
-
For Security group name, enter a descriptive name for the security group, such as
EFA-enabled security group. -
(Optional) For Description, enter a brief description of the security group.
-
For VPC, select the VPC into which you intend to launch your EFA-enabled instances.
-
Choose Create security group.
-
-
Select the security group that you created, and on the Details tab, copy the Security group ID.
-
With the security group still selected, choose Actions, Edit inbound rules, and then do the following:
-
Choose Add rule.
-
For Type, choose All traffic.
-
For Source type, choose Custom and paste the security group ID that you copied into the field.
-
Choose Add rule.
-
For Type, choose SSH.
-
For Source type, choose Anywhere-IPv4.
-
Choose Save rules.
-
-
With the security group still selected, choose Actions, Edit outbound rules, and then do the following:
-
Choose Add rule.
-
For Type, choose All traffic.
-
For Destination type, choose Custom and paste the security group ID that you copied into the field.
-
Choose Save rules.
-
Step 2: Launch a temporary instance
Launch a temporary instance that you can use to install and configure the EFA software components. You use this instance to create an EFA-enabled AMI from which you can launch your EFA-enabled instances.
Step 3: Install the EFA software
Install the EFA-enabled kernel, EFA drivers, Libfabric, and Open MPI stack that is required to support EFA on your temporary instance.
The steps differ depending on whether you intend to use EFA with Open MPI, with Intel MPI, or with Open MPI and Intel MPI.
To install the EFA software
-
Connect to the instance you launched. For more information, see Connect to your Linux instance.
-
To ensure that all of your software packages are up to date, perform a quick software update on your instance. This process may take a few minutes.
-
Amazon Linux 2, RHEL 7/8, and CentOS 7
$sudo yum update -y -
Ubuntu 18.04 and 20.04
$sudo apt-get update$sudo apt-get upgrade -y -
SUSE Linux Enterprise
$sudo zypper update -y
-
-
Download the EFA software installation files. The software installation files are packaged into a compressed tarball (
.tar.gz) file. To download the latest stable version, use the following command.$curl -O https://efa-installer.amazonaws.com/aws-efa-installer-1.19.0.tar.gzYou can also get the latest version by replacing the version number with
latestin the preceding command. -
(Optional) Verify the authenticity and integrity of the EFA tarball (
.tar.gz) file. We recommend that you do this to verify the identity of the software publisher and to check that the file has not been altered or corrupted since it was published. If you do not want to verify the tarball file, skip this step.Note Alternatively, if you prefer to verify the tarball file by using an MD5 or SHA256 checksum instead, see Verify the EFA installer using a checksum.
-
Download the public GPG key and import it into your keyring.
$wget https://efa-installer.amazonaws.com/aws-efa-installer.key && gpg --import aws-efa-installer.keyThe command should return a key value. Make a note of the key value, because you need it in the next step.
-
Verify the GPG key's fingerprint. Run the following command and specify the key value from the previous step.
$gpg --fingerprintkey_valueThe command should return a fingerprint that is identical to
4E90 91BC BB97 A96B 26B1 5E59 A054 80B1 DD2D 3CCC. If the fingerprint does not match, don't run the EFA installation script, and contact AWS Support. -
Download the signature file and verify the signature of the EFA tarball file.
$wget https://efa-installer.amazonaws.com/aws-efa-installer-1.19.0.tar.gz.sig && gpg --verify ./aws-efa-installer-1.19.0.tar.gz.sigThe following shows example output.
gpg: Signature made Wed 29 Jul 2020 12:50:13 AM UTC using RSA key ID DD2D3CCC gpg: Good signature from "Amazon EC2 EFA <ec2-efa-maintainers@amazon.com>" gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner. Primary key fingerprint: 4E90 91BC BB97 A96B 26B1 5E59 A054 80B1 DD2D 3CCCIf the result includes
Good signature, and the fingerprint matches the fingerprint returned in the previous step, proceed to the next step. If not, don't run the EFA installation script, and contact AWS Support.
-
-
Extract the files from the compressed
.tar.gzfile and navigate into the extracted directory.$tar -xf aws-efa-installer-1.19.0.tar.gz && cd aws-efa-installer -
Install the EFA software. Do one of the following depending on your use case.
Note If you are using a SUSE Linux operating system, you must additionally specify the
--skip-kmodoption to prevent kmod installation. By default, SUSE Linux does not allow out-of-tree kernel modules. As a result, EFA and NVIDIA GPUDirect support is currently not supported with SUSE Linux.-
Open MPI and Intel MPI
If you intend to use an EFA with Open MPI and Intel MPI, you must install the EFA software with Libfabric and Open MPI, and you must complete Step 5: (Optional) Install Intel MPI. To install the EFA software with Libfabric and Open MPI, run the following command.
$sudo ./efa_installer.sh -yLibfabric is installed in the
/opt/amazon/efadirectory, while Open MPI is installed in the/opt/amazon/openmpidirectory. -
Open MPI only
If you intend to use EFA with Open MPI only, you must install the EFA software with Libfabric and Open MPI, and you can skip Step 5: (Optional) Install Intel MPI. To install the EFA software with Libfabric and Open MPI, run the following command.
$sudo ./efa_installer.sh -yLibfabric is installed in the
/opt/amazon/efadirectory, while Open MPI is installed in the/opt/amazon/openmpidirectory. -
Intel MPI only
If you intend to use EFA with Intel MPI only, you can install the EFA software without Libfabric and Open MPI. In this case, Intel MPI uses its embedded Libfabric. If you choose to do this, you must complete Step 5: (Optional) Install Intel MPI.
To install the EFA software without Libfabric and Open MPI, run the following command.
$sudo ./efa_installer.sh -y --minimal
-
-
If the EFA installer prompts you to reboot the instance, do so and then reconnect to the instance. Otherwise, log out of the instance and then log back in to complete the installation.
-
Confirm that the EFA software components were successfully installed.
$fi_info -p efa -t FI_EP_RDMThe command should return information about the Libfabric EFA interfaces. The following example shows the command output.
provider: efa fabric: EFA-fe80::94:3dff:fe89:1b70 domain: efa_0-rdm version: 2.0 type: FI_EP_RDM protocol: FI_PROTO_EFA
Step 4: Disable ptrace protection
To improve your HPC application's performance, Libfabric uses the instance's local memory for interprocess communications when the processes are running on the same instance.
The shared memory feature uses Cross Memory Attach (CMA), which is not supported with ptrace protection. If you are using a Linux distribution that has ptrace protection enabled by default, such as Ubuntu, you must disable it. If your Linux distribution does not have ptrace protection enabled by default, skip this step.
To disable ptrace protection
Do one of the following:
-
To temporarily disable ptrace protection for testing purposes, run the following command.
$sudo sysctl -w kernel.yama.ptrace_scope=0 -
To permanently disable ptrace protection, add
kernel.yama.ptrace_scope = 0to/etc/sysctl.d/10-ptrace.confand reboot the instance.
Step 5: (Optional) Install Intel MPI
If you intend to only use Open MPI, skip this step. Perform this step only if you intend to use Intel MPI.
Intel MPI requires an additional installation and environment variable configuration.
Prerequisites
Ensure that the user performing the following steps has sudo permissions.
To install Intel MPI
-
To download the Intel MPI installation script, do the following
-
Visit the Intel website
. -
In the Intel MPI Library section of the webpage, choose the link for the Intel MPI Library for Linux Offline installer.
-
-
Run the installation script that you downloaded in the previous step.
$sudo bashinstallation_script_name.sh -
In the installer, choose Accept & install.
-
Read the Intel Improvement Program, choose the appropriate option, and then choose Begin Installation.
-
When the installation completes, choose Close.
-
By default, Intel MPI uses its embedded (internal) Libfabric. You can configure Intel MPI to use the Libfabric that ships with the EFA installer instead. Typically, the EFA installer ships with a later version of Libfabric than Intel MPI. In some cases, the Libfabric that ships with the EFA installer is more performant than that of Intel MPI. To configure Intel MPI to use the Libfabric that ships with the EFA installer, do one of the following depending on your shell.
-
Add the following source command to your shell script to source the
vars.shscript from the installation directory to set up the compiler environment each time the instance starts. Do one of the following depending on your shell. -
By default, if EFA is not available due to a misconfiguration, Intel MPI defaults to the TCP/IP network stack, which might result in slower application performance. You can prevent this by setting
I_MPI_OFI_PROVIDERtoefa. This causes Intel MPI to fail with the following error if EFA is not available:Abort (XXXXXX) on node 0 (rank 0 in comm 0): Fatal error in PMPI_Init: OtherMPI error, MPIR_Init_thread (XXX)........: MPID_Init (XXXX)..............: MPIDI_OFI_mpi_init_hook (XXXX): open_fabric (XXXX)............: find_provider (XXXX)..........: OFI fi_getinfo() failed (ofi_init.c:2684:find_provider:Do one of the following depending on your shell.
-
By default, Intel MPI doesn't print debugging information. You can specify different verbosity levels to control the debugging information. Possible values (in order of the amount of detail they provide) are:
0(default),1,2,3,4,5. Level1and higher prints thelibfabric versionandlibfabric provider. Uselibfabric versionto check whether Intel MPI is using the internal Libfabric or the Libfabric that ships with the EFA installer. If it's using the internal Libfabric, the version is suffixed withimpi. Uselibfabric providerto check with Intel MPI is using EFA or the TCP/IP network. If it's using EFA, the value isefa. If it's using TCP/IP, the value istcp;ofi_rxm.To enable debugging information, do one of the following depending on your shell.
-
By default, Intel MPI uses the operating system’s shared memory (
shm) for intra-node communication, and it uses Libfabric (ofi) only for inter-node communication. Generally, this configuration provides the best performance. However, in some cases the Intel MPI shm fabric can cause certain applications to hang indefinitely.To resolve this issue, you can force Intel MPI to use Libfabric for both intra-node and inter-node communication. To do this, do one of the following depending on your shell.
Note The EFA Libfabric provider uses the operating system's shared memory for intra-node communication. This means that setting
I_MPI_FABRICStoofiyields similar performance to the defaultshm:oficonfiguration. -
Log out of the instance and then log back in.
-
Run the following command to confirm that Intel MPI was successfully installed.
$which mpiccEnsure that the returned path includes the
/opt/intel/subdirectory.
If you no longer want to use Intel MPI, remove the environment variables from the shell startup scripts.
Step 6: Install your HPC application
Install the HPC application on the temporary instance. The installation procedure varies depending on the specific HPC application. For more information, see Manage software on your Amazon Linux instance.
You might need to refer to your HPC application’s documentation for installation instructions.
Step 7: Create an EFA-enabled AMI
After you have installed the required software components, you create an AMI that you can reuse to launch your EFA-enabled instances.
To create an AMI from your temporary instance
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
. -
In the navigation pane, choose Instances.
-
Select the temporary instance that you created and choose Actions, Image, Create image.
-
For Create image, do the following:
-
For Image name, enter a descriptive name for the AMI.
-
(Optional) For Image description, enter a brief description of the purpose of the AMI.
-
Choose Create image.
-
-
In the navigation pane, choose AMIs.
-
Locate the AMI tht you created in the list. Wait for the status to change from
pendingtoavailablebefore continuing to the next step.
Step 8: Launch EFA-enabled instances into a cluster placement group
Launch your EFA-enabled instances into a cluster placement group using the EFA-enabled AMI that you created in Step 7, and the EFA-enabled security group that you created in Step 1.
-
It is not an absolute requirement to launch your EFA-enabled instances into a cluster placementgroup. However, we do recommend running your EFA-enabled instances in a cluster placement group as it launches the instances into a low-latency group in a single Availability Zone.
-
To ensure that capacity is available as you scale your cluster’s instances, you can create a Capacity Reservation for your cluster placement group. For more information, see Capacity Reservations in cluster placement groups.
Step 9: Terminate the temporary instance
At this point, you no longer need the temporary instance that you launched. You can terminate the instance to stop incurring charges for it.
To terminate the temporary instance
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/
. -
In the navigation pane, choose Instances.
-
Select the temporary instance that you created and then choose Actions, Instance state, Terminate instance.
-
When prompted for confirmation, choose Terminate.
Step 10: Enable passwordless SSH
To enable your applications to run across all of the instances in your cluster, you must enable passwordless SSH access from the leader node to the member nodes. The leader node is the instance from which you run your applications. The remaining instances in the cluster are the member nodes.
To enable passwordless SSH between the instances in the cluster
-
Select one instance in the cluster as the leader node, and connect to it.
-
Disable
strictHostKeyCheckingand enableForwardAgenton the leader node. Open~/.ssh/configusing your preferred text editor and add the following.Host * ForwardAgent yes Host * StrictHostKeyChecking no -
Generate an RSA key pair.
$ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsaThe key pair is created in the
$HOME/.ssh/directory. -
Change the permissions of the private key on the leader node.
$chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/config -
Open
~/.ssh/id_rsa.pubusing your preferred text editor and copy the key. -
For each member node in the cluster, do the following:
-
Connect to the instance.
-
Open
~/.ssh/authorized_keysusing your preferred text editor and add the public key that you copied earlier.
-
-
To test that the passwordless SSH is functioning as expected, connect to your leader node and run the following command.
$sshmember_node_private_ipYou should connect to the member node without being prompted for a key or password.

