Using Advanced Intel® C++ Compiler Features for Android* Applications

Published:10/14/2013   Last Updated:10/14/2013


Using Intel® Cilk™ Plus Runtime on Android to multithread your application

Intel® Cilk™ Plus is an extension to C and C++ that offers a quick and easy way to harness the power of both multicore and vector processing. The three Intel Cilk Plus keywords provide a simple yet surprisingly powerful model for parallel programming, while runtime and template libraries offer a well-tuned environment for building parallel applications.

Using Intel Cilk Plus to multithread your applications requires to link against the Cilk Runtime Library (

Developing with the Intel C++ compiler and the NDK build system (ndk-build)

The NDK build system does not link C++ libraries for modules written in C, as a result the compiler cannot choose the correct Intel Cilk Plus library during linking and this could result in linking errors.

1. Add an empty C++ file to the project to enable C++ linking in the NDK build system

2. Specify compatible C++ implementation in the file:

  • 'APP_STL:=c++_shared' or
  • 'APP_STL:=stlport_shared' or
  • 'APP_STL:=gnustl_static' or
  • 'APP_STL:=gnustl_shared'

3. Modify your Java code as explained in the section "Preparing JNI calls" below

Developing with the standalone Intel C++ compiler without the NDK build system (ndk-build)

If your development environment consists of C++ code you need to explicitly link against either the GNU_STL library or the stlport library.

Please following the steps below:

1. Specify the following flags for linking and compilation for the corresponding C++ implementation included in NDK like:

  • Compilation flags:
    -I$ANDROID_GNU_LIBSTDCPP/include -I$ANDROID_GNU_LIBSTDCPP/libs/<arch>/include
  • Linking flags (gnustl_shared):
    -L$ANDROID_GNU_LIBSTDCPP/libs/<arch>-lgnustl_shared -lsupc++
  • Linking flags (gnustl_static):
    -L$ANDROID_GNU_LIBSTDCPP/libs/<arch> -lgnustl_static -lsupc++

ANDROID_GNU_LIBSTDCPP=$NDK/sources/cxx-stl/gnu-libstdc++/4.6. 4.6 should be replaced with GCC version pointed to by ANDROID_GNU_X86_TOOLCHAIN. For example, if ANDROID_GNU_X86_TOOLCHAIN points to $NDK/toolchains/x86-4.8/prebuilt/linux-x86, then 4.6 should be replaced with 4.8. <arch> needs to be replaced by x86 or x86_64.
When using Intel Cilk Plus you need to link against the library. This library is located in the /compiler/lib/ia32/gnustl directory.

2. If stlport_shared C++ library (need at least NDK r9) is used, add following flags:

  • Compilation flags:
  • Linking flags:
    -L$ANDROID_STLPORT_LIBSTDCPP/libs/<arch> -lstlport_shared

<arch> needs to be replaced by x86 or x86_64.

When using Intel Cilk Plus, the corresponding library is located in the /compiler/lib/<arch>_and/stlport directory.

3. If c++_shared C++ library (need at least NDK r10) is used, add following flags:

  • Compilation flags:
    -I$ANDROID_LLVM_LIBSTDCPP/libcxx/include -I$ ANDROID_LLVM_LIBSTDCPP / ../../android/support/include
  • Linking flags:
    -L$ANDROID_LLVM_LIBSTDCPP/libs/<arch> -lc++_shared



The <arch> is x86 or x86_64.

When using Intel Cilk Plus, the corresponding library is located in the /compiler/lib/<arch>_and/llvmstl directory.

Preparing JNI calls

Preparing JNI calls are required for using Intel Cilk Plus for all Android versions prior Android 4.3 (Jelly Bean MR2). ‘’ library needs to be loaded from Java Code with following API call:

If your application depends on dynamic C++ implementation, then you need to load additional corresponding library besides






Using PGO to Improve Android* OS Application Performance

Profile-guided Optimization (PGO) improves application performance by reorganizing code layout to reduce instruction-cache problems, shrinking code size, and reducing branch mispredictions. PGO provides information to the compiler about areas of an application that are most frequently executed. By knowing these areas, the compiler is able to be more selective and specific in optimizing the application.

Using PGO on Android requires some additional steps compared to the usage on other Operating System.

1. Add the following options to the C flags in the jni/ file:
LOCAL_CFLAGS:= -prof-gen -prof-dir /sdcard

2. Add the WRITE_EXTERNAL_STORAGE permission to allow the application writing the PGO output to the sdcard folder. Add the following line to the AndroidManifest.xml file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

3. Ensure that the profiling data gets written. The profiling data is written in default mode only if the application exits. Usually an application on Android* does not exit. Use the following options to enforce the application exit or to work around this issue:

a. Option 1: Call exit from JAVA code:



b. Option 2: Explicitly dump PGO data from the native code:

#include <pgouser.h>


c. Option 3: Use environment variables to write the performance data regularly to the sdcard while the application is running. To make the environment variables available for all applications, add them to the init.rc file of the Android Image:



NOTE: The value INTEL_PROF_DUMP_INTERVAL is measured in microsecond and should not be greater than INT_MAX.

4. Copy the generated dyn files from the target to the host in the source directory of the application:

adb pull ...


5. Change the C flags in file to use the generated dyn files. You can use the -prof-dir parameter to point to a different file location.
LOCAL_CFLAGS := -prof-use

See Profile-Guided Optimizations section in the Intel® C++ Compiler XE 15.0 User and Reference Guides supplied with the package for information on using PGO for optimizing applications built with the Intel(R) C++ Compiler on Linux*, Windows*, and OS X* operating systems.

Other Related Articles and Resources

Intel® System Studio - Multicore Programming with Intel® Cilk™ Plus
Intel® Cilk™ Plus
User and Reference Guide for the Intel® C++ Compiler 15.0
Android* NDK for Intel® Architecture
Using the Android* x86 NDK with Eclipse* and Porting an NDK Sample App

To learn more about Intel tools for the Android developer, visit Intel® Developer Zone for Android.

Product and Performance Information


Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804