diff --git a/mpi_assignment/MPI/Makefile b/mpi_assignment/MPI/Makefile new file mode 100644 index 0000000..640e68c --- /dev/null +++ b/mpi_assignment/MPI/Makefile @@ -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 \ No newline at end of file diff --git a/mpi_assignment/MPI/hello.c b/mpi_assignment/MPI/hello.c new file mode 100644 index 0000000..7146ffd --- /dev/null +++ b/mpi_assignment/MPI/hello.c @@ -0,0 +1,27 @@ +#include +#include + +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(); +} \ No newline at end of file diff --git a/mpi_assignment/MPI/remotes.txt b/mpi_assignment/MPI/remotes.txt new file mode 100644 index 0000000..fc69b37 --- /dev/null +++ b/mpi_assignment/MPI/remotes.txt @@ -0,0 +1,4 @@ +kaiju +kraken +gojiro +tsunami \ No newline at end of file diff --git a/mpi_assignment/MPI/setup_remotes.py b/mpi_assignment/MPI/setup_remotes.py new file mode 100644 index 0000000..618a31c --- /dev/null +++ b/mpi_assignment/MPI/setup_remotes.py @@ -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()