Commit 5a45d17a by Hyacinthe Cartiaux

Syntax

parent 6a786c60
......@@ -785,17 +785,17 @@ On a node, using an interactive jobs, you can:
This code will calculate the first N numbers of the Fibonacci sequence
N=1000;
fib=zeros(1,N);
fib(1)=1;
fib(2)=1;
k=3;
while k <= N
fib(k)=fib(k-2)+fib(k-1);
fprintf('%d\n',fib(k));
pause(1);
k=k+1;
end
N=1000;
fib=zeros(1,N);
fib(1)=1;
fib(2)=1;
k=3;
while k <= N
fib(k)=fib(k-2)+fib(k-1);
fprintf('%d\n',fib(k));
pause(1);
k=k+1;
end
2. Create a new interactive job
......@@ -815,15 +815,15 @@ On a node, using an interactive jobs, you can:
This code will calculate the first N numbers of the Fibonacci sequence
N <- 130
fibvals <- numeric(N)
fibvals[1] <- 1
fibvals[2] <- 1
for (i in 3:N) {
fibvals[i] <- fibvals[i-1]+fibvals[i-2]
print( fibvals[i], digits=22)
Sys.sleep(1)
}
N <- 130
fibvals <- numeric(N)
fibvals[1] <- 1
fibvals[2] <- 1
for (i in 3:N) {
fibvals[i] <- fibvals[i-1]+fibvals[i-2]
print( fibvals[i], digits=22)
Sys.sleep(1)
}
2. Create a new interactive job
......@@ -833,7 +833,7 @@ On a node, using an interactive jobs, you can:
4. Execute the code using R
(node)$> Rscript path/to/fibonacci.R
(node)$> Rscript path/to/fibonacci.R
......@@ -846,25 +846,25 @@ In this section, we will learn to compile small "hello world" programs in differ
Create a new file called `helloworld.c`, containing the source code of a simple "Hello World" program written in C.
#include<stdio.h>
int main()
{
printf("Helloi, world!");
return 0;
}
#include<stdio.h>
int main()
{
printf("Hello, world!");
return 0;
}
First, compile the program using the "FOSS" toochain, containing the GNU C compiler
(node)$> module load toolchain/foss
(node)$> gcc helloworld.c -o helloworld
(node)$> module load toolchain/foss
(node)$> gcc helloworld.c -o helloworld
Then, compile the program using the Intel toolchain, containing the ICC compiler
(node)$> module purge
(node)$> module load toolchain/intel
(node)$> icc helloworld.c -o helloworld
(node)$> module purge
(node)$> module load toolchain/intel
(node)$> icc helloworld.c -o helloworld
If you use Intel CPUs and ICC is available on the platform, it is advised to use ICC in order to produce optimized binaries and achieve better performance.
......@@ -875,11 +875,11 @@ If you use Intel CPUs and ICC is available on the platform, it is advised to use
compile the following program, using GNU C++ compiler (`g++` command), and the Intel compiler (`icpc` command).
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
}
#include <iostream>
int main() {
std::cout << "Hello, world!" << std::endl;
}
......@@ -889,9 +889,9 @@ compile the following program, using GNU C++ compiler (`g++` command), and the I
compile the following program, using the GNU Fortran compiler (`gfortran` command), and ICC (`ifortran` command).
program hello
print *, "Hello, World!"
end program hello
program hello
print *, "Hello, World!"
end program hello
Be careful, the 6 spaces at the beginning of each line are required
......@@ -908,55 +908,55 @@ Then, each process prints its rank, the total number of processes and the value
In your home directory, create a file `mpi_broadcast.c` and copy the following source code:
#include <stdio.h>
#include <mpi.h>
#include <unistd.h>
#include <time.h> /* for the work function only */
int main (int argc, char *argv []) {
char hostname[257];
int size, rank;
int i, pid;
int bcast_value = 1;
gethostname(hostname, sizeof hostname);
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (!rank) {
bcast_value = 42;
}
MPI_Bcast(&bcast_value,1 ,MPI_INT, 0, MPI_COMM_WORLD );
printf("%s\t- %d - %d - %d\n", hostname, rank, size, bcast_value);
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
#include <stdio.h>
#include <mpi.h>
#include <unistd.h>
#include <time.h> /* for the work function only */
int main (int argc, char *argv []) {
char hostname[257];
int size, rank;
int i, pid;
int bcast_value = 1;
gethostname(hostname, sizeof hostname);
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (!rank) {
bcast_value = 42;
}
MPI_Bcast(&bcast_value,1 ,MPI_INT, 0, MPI_COMM_WORLD );
printf("%s\t- %d - %d - %d\n", hostname, rank, size, bcast_value);
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Reserve 2 cores on two distinct node with OAR
(access-gaia)$> oarsub -I -l nodes=2/core=1
(access-gaia)$> oarsub -I -l nodes=2/core=1
or with Slurm
(access-iris)$> srun -p interactive --qos qos-interactive --time 1:00:0 -N 2 -n 2 --pty bash
(access-iris)$> srun -p interactive --qos qos-interactive --time 1:00:0 -N 2 -n 2 --pty bash
Load a toolchain and compile the code using `mpicc`
(node)$> mpicc mpi_broadcast.c -o mpi_broadcast -lpthread
(node)$> mpicc mpi_broadcast.c -o mpi_broadcast -lpthread
If you use OAR, execute your mpi program using `mpirun`.
Note that the `-n` parameter of mpirun is the number of processes, which should be equal to the number of reserved cpu cores most of the time.
(node)$> OAR_NTASKS=$(cat $OAR_NODEFILE | wc)
(node)$> mpirun -n $OAR_NTASKS -hostfile $OAR_NODEFILE ~/mpi_broadcast
(node)$> OAR_NTASKS=$(cat $OAR_NODEFILE | wc)
(node)$> mpirun -n $OAR_NTASKS -hostfile $OAR_NODEFILE ~/mpi_broadcast
If you use Slurm, you can use the `srun` command. Create an interactive job, with 2 nodes (`-N 2`), and at least 2 tasks (`-n 2`).
(node)$> srun -n $SLURM_NTASKS ~/mpi_broadcast
(node)$> srun -n $SLURM_NTASKS ~/mpi_broadcast
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment