Click for detailed status
C/C++
C and C++ are ISO-standardized, general-purpose, compiled programming languages widely used for system programming, embedded systems, and high-performance applications.
C/C++ compilers on Euler¶
On Euler the following C/C++ compilers are available via modules:
| Compiler | Module Command |
|---|---|
| gcc 12.2.0 | module load stack/2024-06 |
| gcc 8.5.0 | module load stack/2024-04 |
| Intel oneAPI 2023.2.0 | module load stack/2024-06 intel-oneapi-compilers/2023.2.0 |
Note: Intel OneAPI 2023.2.0 provides both classical compilers (
icpc,icc) and LLVM-based compilers (icpx,icx). This is the last release with classical compilers; newer releases will only provide LLVM-based compilers.
The worldwide C/C++ community¶
Discord
YouTube
Example programs¶
Hello world¶
Create a file hello.c containing
Multi-threading with OpenMP¶
OpenMP enables multiprocessing and concurrent threads.
Create a file hello_omp.c containing
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d of %d\n", omp_get_thread_num(), omp_get_num_threads());
return 0;
}
Hello from thread 0 of 8
Hello from thread 3 of 8
Hello from thread 1 of 8
Hello from thread 4 of 8
Hello from thread 2 of 8
Hello from thread 7 of 8
Hello from thread 6 of 8
Hello from thread 5 of 8
Communication via MPI¶
Message Passing Interface (MPI) enables inter-process communication.
Create a file hello_mpi.c containing
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
MPI_Init(&argc, &argv);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
printf("Hello from process %d out of %d!\n", world_rank, world_size);
MPI_Finalize();
return 0;
}
module load stack/2024-06 gcc/12.2.0 openmpi/4.1.6
mpicc hello_mpi.c -o hello_mpi
srun -n 4 hello_mpi
Hello from process 0 out of 4!
Hello from process 2 out of 4!
Hello from process 3 out of 4!
Hello from process 1 out of 4!
Targeting GPUs with CUDA¶
CUDA enables GPU computing.
Create a file hello_cuda.cu containing