Compiling OmpSs-2 programs using the LLVM-based compiler¶
C/C++ programs¶
Following is a very simple OmpSs-2 program in C:
/* test.c */
#include <stdio.h>
int main(int argc, char *argv[])
{
int x = argc;
#pragma oss task inout(x)
{
x++;
}
#pragma oss task in(x)
{
printf("argc + 1 == %d\n", x);
}
#pragma oss taskwait
return 0;
}
Compile it using clang and the -fompss-2 flag:
$ clang -o test -fompss-2 test.c
Important
Do not forget the flag -fompss-2 in both compilation and linking stages of your application.
Otherwise, your application will not be compiled with parallel support or not linked to the tasking runtime library.
And run it:
$ ./test
argc + 1 == 2
Use the driver clang++ to compile C++ applications:
/* test.cpp */
#include <iostream>
template <typename T>
void test(T x)
{
T t = x;
#pragma oss task inout(x)
{
x *= 2;
}
#pragma oss task in(x)
{
std::cout << t << " * 2 == " << x << "\n";
}
#pragma oss taskwait
}
int main(int argc, char *argv[])
{
test(42);
test(84.1);
return 0;
}
Compile it using clang++ and the -fompss-2 flag:
$ clang++ -o test -fompss-2 test.cpp
And run it:
$ ./test
42 * 2 = 84
84.1 * 2 = 168.2
Choosing between Nanos6 and NODES runtimes¶
As stated in Installation of LLVM-based compiler, our LLVM/Clang can compile OmpSs-2 programs targeting the Nanos6 or the NODES runtime systems. LLVM/Clang follows the order below to decide which runtime system to target when compiling an OmpSs-2 program. The list is ordered from most to least priority:
The LLVM/Clang’s
-fompss-2flag accepts an optional value to explicitly choose the runtime library when compiling an application. The accepted values arelibnano6andlibnodes. For instance, the flag-fompss-2=libnanos6will make the application to target the Nanos6 runtimeOtherwise, LLVM/Clang reads the
OMPSS2_RUNTIMEenvironment variable when compiling or linking OmpSs-2 applications. Similarly, the accepted values for the envar arelibnanos6andlibnodesLastly, LLVM/Clang uses the default runtime specified through the
CLANG_DEFAULT_OMPSS2_RUNTIMECMake option at the building stage. As shown in Installation of LLVM-based compiler, thelibnodesis the default if not specified
Notice that is user’s responsability to provide the same runtime value when compiling and linking all source code files of the same application.
Once a runtime has been chosen, clang has to decide which is the path where it can find
that runtime library. The compiler uses the runtime library directory following these rules
from most to least priority:
LLVM/Clang reads the
NANOS6_HOMEorNODES_HOMEenvironment variables to know the installation path of Nanos6 and NODES, respectively. If defined, the default paths to the the runtimes provided at the building stage are ignoredOtherwise, the paths provided through the
CLANG_DEFAULT_NANOS6_HOMEandCLANG_DEFAULT_NODES_HOMECMake options at the building stage are used. See Installation of LLVM-based compiler
The LLVM/Clang compiler defines the _OMPSS_2 preprocessor macro when compiling an OmpSs-2 program, as required by the OmpSs-2 Specification.
Additionally, the compiler defines the _OMPSS_2_NANOS6 or _OMPSS_2_NODES preprocessor macros depending on the chosen runtime.
This way, the programmer can determine the target runtime from the application’s code, e.g., for including runtime-specific headers.