[araim1@tara-fe1 ~]$ wget <paste_the_link_here>
[araim1@tara-fe1 ~]$ wget http://www.umbc.edu/hpcf/code/hello_serial/hello_serial.c --16:08:24-- http://www.umbc.edu/hpcf/code/hello_serial/hello_serial.c Resolving www.umbc.edu... 130.85.12.11 Connecting to www.umbc.edu|130.85.12.11|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 183 [text/plain] Saving to: `hello_serial.c' 100%[======================================================================================>] 183 --.-K/s in 0s 16:08:24 (29.1 MB/s) - `hello_serial.c' saved [183/183] [araim1@tara-fe1 ~]$ ls hello_serial.c [araim1@tara-fe1 ~]$
#include <stdio.h> #include <unistd.h> int main(int argc, char* argv[]) { char hostname[256]; gethostname(hostname, 256); printf("Hello world from %s\n", hostname); return 0; }
[araim1@tara-fe1 hello_serial]$ pgcc hello_serial.c -o hello_serial [araim1@tara-fe1 hello_serial]$
[araim1@tara-fe1 hello_serial]$ ls hello_serial hello_serial.c
#include <stdio.h> #include <mpi.h> int main (int argc, char *argv[]) { int id, np; char processor_name[MPI_MAX_PROCESSOR_NAME]; int processor_name_len; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Get_processor_name(processor_name, &processor_name_len); printf("Hello world from process %03d out of %03d, processor name %s\n", id, np, processor_name); MPI_Finalize(); return 0; }
[araim1@tara-fe1 hello_parallel]$ mpicc hello_parallel.c -o hello_parallel hello_parallel.c: [araim1@tara-fe1 hello_parallel]$
[araim1@tara-fe1 hello_parallel]$ ls hello_parallel hello_parallel.c [araim1@tara-fe1 hello_parallel]$
[araim1@tara-fe1 results]$ switcher --show mpi user:default=pgi-9.0-mvapich2-1.4rc2 user:exists=1 [araim1@tara-fe1 ~]$
[araim1@tara-fe1 results]$ switcher --list mpi pgi-9.0-mvapich2-1.4rc2 gcc-mvapich2-1.4rc2 pgi-9.0-openmpi-1.3.3-p1 gcc-openmpi-1.3.3 gcc-openmpi-1.3.3-p1 pgi-9.0-openmpi-1.3.3 [araim1@tara-fe1 ~]$
[araim1@tara-fe1 ~]$ switcher mpi = gcc-openmpi-1.3.3-p1 Warning: mpi:default already has a value: pgi-9.0-mvapich2-1.4rc2 Replace old attribute value (y/N)? y Attribute successfully set; new attribute setting will be effective for future shells [araim1@tara-fe1 ~]$
[araim1@tara-fe1 ~]$ switcher_reload [araim1@tara-fe1 ~]$
[araim1@tara-fe1 ~]$ mpicc -show pgcc -g -I/usr/cluster/mvapich2/1.4rc2-2/pgi/9.0/include -L/usr/cluster/mvapich2 /1.4rc2-2/pgi/9.0/lib -Wl,-rpath,/usr/cluster/mvapich2/1.4rc2-2/pgi/9.0/lib -lmp ich -lpmi -lpthread -lrdmacm -libverbs -libumad -lrt [araim1@tara-fe1 ~]$
#include <stdio.h> #include <mpi.h> #include <string.h> int main(int argc, char* argv[]) { int id, np, processor_name_len; int j; int dest; int tag = 0; char processor_name[MPI_MAX_PROCESSOR_NAME]; char message[100]; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Get_processor_name(processor_name, &processor_name_len); sprintf(message, "Process %03d out of %03d running on processor %4s", id, np, processor_name); if (id == 0) { printf("%s\n", message); for (j = 1; j < np; j++) { MPI_Recv(message, 100, MPI_CHAR, j, tag, MPI_COMM_WORLD, &status); printf("%s\n", message); } } else { dest = 0; MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD); } MPI_Finalize(); return 0; }
#include <stdio.h> #include <mpi.h> #include "nodes_used.h" int main(int argc, char* argv[]) { int id, np, processor_name_len; char processor_name[MPI_MAX_PROCESSOR_NAME]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &id); MPI_Comm_size(MPI_COMM_WORLD, &np); MPI_Get_processor_name(processor_name, &processor_name_len); FILE* log_fp = NULL; if (id == 0) { log_fp = fopen("nodes_used.log", "w"); } /* Log our MPI processes to the log file. We could also have specified the special FILE* names "stdout" or "stderr" here */ log_processes(log_fp, id, np, processor_name); if (id == 0) { fclose(log_fp); } MPI_Finalize(); return 0; }
#ifndef NODES_USED_H #define NODES_USED_H #include <stdio.h> #include <string.h> #include <mpi.h> void log_processes(FILE* fp, int id, int np, char* processor_name); #endif
#include "nodes_used.h" void log_processes(FILE* fp, int id, int np, char* processor_name) { int j, dest; char message[100]; int tag = 0; MPI_Status status; sprintf(message, "Process %04d out of %04d running on processor %4s", id, np, processor_name); if (id == 0) { fprintf(fp, "%s\n", message); for (j = 1; j < np; j++) { MPI_Recv(message, 100, MPI_CHAR, j, tag, MPI_COMM_WORLD, &status); fprintf(fp, "%s\n", message); } } else { dest = 0; MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD); } }
OBJS := nodes_used.o hello_send_recv.o EXECUTABLE := hello_send_recv DEFS := CFLAGS := -g -O3 INCLUDES := LDFLAGS := -lm CC := mpiicc %.o: %.c %.h $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ $(EXECUTABLE): $(OBJS) $(CC) $(CFLAGS) $(INCLUDES) $(OBJS) -o $@ $(LDFLAGS) clean: rm -f *.o $(EXECUTABLE)
[araim1@tara-fe1 hello_send_recv-2]$ make mpicc -g -O3 -c nodes_used.c -o nodes_used.o mpicc -g -O3 -c -o hello_send_recv.o hello_send_recv.c mpicc -g -O3 nodes_used.o hello_send_recv.o -o hello_send_recv -lm [araim1@tara-fe1 hello_send_recv-2]$ ls Makefile nodes_used.c hello_send_recv nodes_used.h hello_send_recv.c nodes_used.o hello_send_recv.o [araim1@tara-fe1 hello_send_recv-2]$
[araim1@tara-fe1 hello_send_recv-2]$ make clean rm -f *.o *.oo hello_send_recv [araim1@tara-fe1 hello_send_recv-2]$ ls Makefile hello_send_recv.c nodes_used.c nodes_used.h [araim1@tara-fe1 hello_send_recv-2]$