mpi example

This commit is contained in:
Ziad Arafat committed 2023-11-07 11:25:59 -07:00
1 parent 1acd922825
commit d75ecce826
4 files changed
+102

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
all: hello
hello: hello.c
mpicc -o hello hello.c
run:
mpirun --hostfile remotes.txt -np 92 ./hello
clean:
rm -f hello
+27
View File
@@ -0,0 +1,27 @@
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// Print off a hello world message
printf("Hello world from processor %s, rank %d out of %d processors\n",
processor_name, world_rank, world_size);
// Finalize the MPI environment.
MPI_Finalize();
}
+4
View File
@@ -0,0 +1,4 @@
kaiju
kraken
gojiro
tsunami
+60
View File
@@ -0,0 +1,60 @@
import paramiko
import os
# Read the input file with the list of hosts, username, and password
import argparse
import paramiko
parser = argparse.ArgumentParser(
description="Configure passwordless ssh for remote hosts"
)
parser.add_argument(
"input_file", type=str, help="path to input file with list of hosts"
)
parser.add_argument("username", type=str, help="username for remote hosts")
parser.add_argument("password", type=str, help="password for remote hosts")
args = parser.parse_args()
with open(args.input_file, "r") as f:
hosts = [line.strip().split()[0] for line in f]
print(hosts)
# For each host in the list, configure ssh key for passwordless ssh
for host in hosts:
# Create a new SSH client
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Connect to the remote host
client.connect(host, username=args.username, password=args.password)
print("Connected to", host)
# Generate an ssh key pair on the remote host
stdin, stdout, stderr = client.exec_command(
'echo -e "y\n" | ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa'
)
print("Generated ssh key pair on", host)
stdout.channel.recv_exit_status()
print("Copying public key to authorized_keys on", host)
# Copy the public key to the remote host's authorized_keys file
stdin, stdout, stderr = client.exec_command(
"cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys"
)
print("Copied public key to authorized_keys on", host)
stdout.channel.recv_exit_status()
# Disconnect from the remote host
client.close()
print("Disconnected from", host)
# Test the ssh connection to the remote host
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=args.username, key_filename=os.path.expanduser("~/.ssh/id_rsa"))
stdin, stdout, stderr = client.exec_command("echo success")
if stdout.read().decode().strip() == "success":
print(f"Successfully configured passwordless ssh for {host}")
else:
print(f"Error configuring passwordless ssh for {host}")
client.close()