In order to enable data race detection in a program, the code must first be instrumented to monitor memory accesses at runtime. The instrumentation can be done on application source code or on the application binary. The tutorial shows how to use both methods of instrumenting the programs.
To instrument the source code, you must compile the application with the special compiler option -xinstrument=datarace. This option instructs the compiler to instrument the generated code for data race detection.
Add the -xinstrument=datarace compiler option to the existing set of options you use to compile your program.
You can use the following commands for instrumenting the source code for the tutorial:
% cc -xinstrument=datarace -g -xopenmp=noopt -o prime_omp_inst prime_omp.c -lm
% cc -xinstrument=datarace -g -o prime_pthr_inst prime_pthr.c -lm
Notice that in the example, the output file is specified with _inst at the end so that you can tell that the binary is the instrumented binary. This is not required.
To instrument a program's binary code instead of the source code, you need to use the discover tool, which is included in Oracle Solaris Studio and is documented in the discover(1) man page and Oracle Solaris Studio 12.4: Discover and Uncover User’s Guide .
For the tutorial examples, type the following command to compile the code:
% cc -xopenmp=noopt -g -o prime_omp prime_omp.c -lm
% cc -g -O2 -o prime_pthr prime_pthr.c -lm
Then run discover on the prime_omp and prime_pthr optimized binaries that you created:
% discover -i datarace -o prime_omp_disc prime_omp
% discover -i datarace -o prime_pthr_disc prime_pthr
These commands create instrumented binaries, prime_omp_disc and prime_pthr_disc that you can use with collect to create experiments that you can examine with Thread Analyzer.