Cray Compiler-specific extensions in C++

Cray Compiler is a high-performance compiler specifically designed for Cray supercomputers. It offers several extensions to the C++ language that can be used to leverage the architecture of these powerful machines. In this blog post, we will explore some of the most important Cray Compiler-specific extensions in C++ and how they can be used to optimize code.

#1. {{ cray_vector }}

The {{cray_vector}} extension is used to enable automatic vectorization in loops. By inserting this directive before a loop, the compiler will perform vectorization on that loop if possible. Vectorization allows the loop to iterate over multiple data elements simultaneously, improving performance by utilizing the SIMD (Single Instruction, Multiple Data) capabilities of the processor.


{{cray_vector}}
for (int i = 0; i < n; ++i) {
    // loop body
}

#2. {{ cray_taskwait }}

The {{cray_taskwait}} extension is used to synchronize the completion of tasks in a parallel region. When this directive is encountered, the executing thread will wait until all the tasks have completed before proceeding further. This ensures that there is no data race or inconsistency when accessing shared resources.


#pragma omp parallel
{
    #pragma omp single
    {
        // spawn multiple tasks
    }

    // other parallel code

    {{cray_taskwait}} // wait for all tasks to complete
}

These are just two examples of the many compiler-specific extensions provided by Cray Compiler. These extensions allow programmers to write more efficient and optimized code for Cray supercomputers, taking full advantage of the architecture. By utilizing these extensions, developers can unlock the full potential of the hardware and achieve better performance.

To learn more about these extensions and other Cray-specific features, refer to the Cray Compiler documentation and programming guides.