@@ -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 */