> sudo apt-get install mpi-default-dev mpi-default-bin
> sudo apt-get install openmpi-bin openmpi-doc libopenmpi-dev
libhwloc-contrib-plugins libtool-doc
>ps -ax |grep sshd
> ssh-keygen > cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys > chmod go-rwx ~/.ssh/authorized_keys > ssh-add
Compiling Code:
> mpicxx [compiler options] skalar.cpp -o main.GCC_
> mpirun -np 4 ./main.GCC_
> mpirun -np 4 --hostfile my_hostfile ./main.GCC_
Changing the underlying Compiler for OpenMPI (briefly):
> export OMPI_CXX=icpc
> export
OMPI_CXX=pgc++
and > export OMPI_CXXFLAGS="-I/usr/lib/openmpi/include
-I/usr/lib/openmpi/include/openmpi"
-pthread
is
not accepted by the PGI compiler, mpicxx -showme:compile |sed 's/-pthread//g'
)export OMPI_CXX=nvcc
export MPICH_CXX=icpc
and mpicxx
-compile_info
How to MPI-parallelize the inner product:
Original code for inner product:double scalar(const int N, const double x[], const double y[]) { double sum = 0.0;
for (int i=0; i<N; ++i) { sum += x[i]*y[i]; } return sum; }
int main()
{
...
double s = scalar(n,a,b);
...
}
#include <mpi.h>
// local sequential inner product
double scalar(const int N, const double x[], const double y[]) { double sum = 0.0;
for (int i=0; i<N; ++i)
sum += x[i]*y[i]; return sum; }
// MPI inner product double scalar(const int n, const double x[], const double y[], const MPI_Comm icomm) { const double s = scalar(n,x,y); // call sequential inner product double sg; MPI_Allreduce(&s,&sg,1,MPI_DOUBLE,MPI_SUM,icomm); return(sg);
}
int main(int argc, char* argv[])
{
...
MPI_Init(&argc,&argv);
...
double s = scalar(n,a,b,MPI_COMM_WORLD);
...
MPI_Finalize();
...
}
> mpicxx
skalar.cpp -o main.GCC_
> mpirun
-np 4 main.GCC_
.See also the exercise sheet.
qsub mephisto_simple_cpu.sh
mephisto_simple_cpu.sh.o<job-ID>
qsub mephisto_adv_cpu.sh
mephisto_adv_cpu.sh.o<job-ID>