...
The following exercises will help you understand how to build your own software on the ATOS HPCF or ECS.
Table of Contents |
---|
...
Before we start...
Ensure your environment is clean by running:
No Format module reset
Create a directory for this tutorial and cd into it:
No Format mkdir -p compiling_tutorial cd compiling_tutorial
Building simple programs
With your favourite editor, create three hello world programs, one in C, one in C++ and one in Fortran
Code Block language cpp title hello.c collapse true #include <stdio.h> int main(int argc, char** argv) { printf("Hello World from a C program\n"); return 0; }
Code Block language cpp title hello++.cc collapse true #include <iostream> int main() { std::cout << "Hello World from a C++ program!" << std::endl; }
Code Block language cpp title hellof.f90 collapse true program hello print *, "Hello World from a Fortran Program!" end program hello
Compile and run each one of them with the GNU compilers (
gcc
,g++
,gfortran
)Expand title Solution We can build them with:
No Format gcc -o hello hello.c g++ -o hello++ hello++.cc gfortran -o hellof hellof.f90
All going well, we should have now the executables that we can run
No Format $ for exe in hello hello++ hellof; do ./$exe; done Hello World from a C program Hello World from a C++ program! Hello World from a Fortran Program!
Now, use the generic environment variables for the different compilers (
$CC
,$CXX
,$FC
) and rerun, you should see no difference to the above results.Expand title Solution We can rebuild them with:
No Format $CC -o hello hello.c $CXX -o hello++ hello++.cc $FC -o hellof hellof.f90
We can now run them exactly in the same way:
No Format $ for exe in hello hello++ hellof; do ./$exe; done Hello World from a C program Hello World from a C++ program! Hello World from a Fortran Program!
Tip title Always use the environment variables for compilers We always recommend using the environment variables since it will make it easier for you to switch to a different compiler.
...