gmake tbb tbbmalloc target=android

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc"
tools:context=".FullscreenActivity" >
<TextView
android:id="@+id/fullscreen_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true"
android:text="@string/dummy_content"
android:textColor="#33b5e5"
android:textSize="50sp"
android:textStyle="bold" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true" >
<LinearLayout
android:id="@+id/fullscreen_content_controls"
style="?buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="74dp"
android:layout_gravity="bottom|center_horizontal"
android:background="@color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent" >
<Button
android:id="@+id/dummy_button1"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button1"
android:onClick="onClickSR" />
<Button
android:id="@+id/dummy_button2"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/dummy_button2"
android:onClick="onClickDR" />
</LinearLayout>
</FrameLayout>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Sample</string>
<string name="dummy_content">Reduce sample</string>
<string name="dummy_button1">Simple Reduce</string>
<string name="dummy_button2">Deterministic Reduce</string>
</resources>
// JNI functions
private native float onClickDRCall();
private native float onClickSRCall();
public void onClickDR(View myView) {
TextView tv=(TextView)(this.findViewById(R.id.fullscreen_content));
float res=onClickDRCall();
tv.setText("Result DR is \n" + res);
}
public void onClickSR(View myView) {
TextView tv=(TextView)(this.findViewById(R.id.fullscreen_content));
float res=onClickSRCall();
tv.setText("Result SR is \n" + res);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
…
System.loadLibrary("tbb");
System.loadLibrary("jni-engine");
}
LOCAL_PATH := $(call my-dir)
TBB_PATH := <path_to_the_package>
include $(CLEAR_VARS)
LOCAL_MODULE := jni-engine
LOCAL_SRC_FILES := jni-engine.cpp
LOCAL_CFLAGS += -DTBB_USE_GCC_BUILTINS -std=c++11 -I$(TBB_PATH)/include
LOCAL_LDLIBS := -ltbb -L./ -L$(TBB_PATH)/<path_to_libtbb_so>
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtbb
LOCAL_SRC_FILES := libtbb.so
include $(PREBUILT_SHARED_LIBRARY)
APP_ABI := x86
APP_GNUSTL_FORCE_CPP_FEATURES := exceptions rtti
APP_STL := system
#include <jni.h>
#include "tbb/parallel_reduce.h"
#include "tbb/blocked_range.h"
float SR_Click()
{
int N=10000000;
float fr = 1.0f/(float)N;
float sum = tbb::parallel_reduce(
tbb::blocked_range<int>(0,N), 0.0f,
[=](const tbb::blocked_range<int>& r, float sum)->float {
for( int i=r.begin(); i!=r.end(); ++i )
sum += fr;
return sum;
},
[]( float x, float y )->float {
return x+y;
}
);
return sum;
}
float DR_Click()
{
int N=10000000;
float fr = 1.0f/(float)N;
float sum = tbb::parallel_deterministic_reduce(
tbb::blocked_range<int>(0,N), 0.0f,
[=](const tbb::blocked_range<int>& r, float sum)->float {
for( int i=r.begin(); i!=r.end(); ++i )
sum += fr;
return sum;
},
[]( float x, float y )->float {
return x+y;
}
);
return sum;
}
extern "C" JNIEXPORT jfloat JNICALL Java_com_example_app1_FullscreenActivity_onClickDRCall(JNIEnv *env, jobject obj)
{
return DR_Click();
}
extern "C" JNIEXPORT jfloat JNICALL Java_com_example_app1_FullscreenActivity_onClickSRCall(JNIEnv *env, jobject obj)
{
return SR_Click();
}

Только зарегистрированные пользователи могут оставлять комментарии. Войдите, пожалуйста.
комментарии (9)