Joydeep Mitra
2017-12-01 18:42:24 UTC
Hi,
I am trying to explore OpenMP in Android. However, my code always runs
using 1 thread even if the max no of threads available is 6. I have tried
to set the no. of threads to 6 but it still runs on only 1. I have also
tried to set the environment variable to 6 but it still doesn't work. Can
anyone provide some insight as to why this is happening? Here is the code I
am using.
jdouble Java_edu_example_anative_myfirstnativeapp_MyNative_calcPipar(){
int i,j;
int tid;
double x;
double pi, sum = 0.0;
double start, delta;
step = 1.0/(double) steps;
sum = 0.0;
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Max Threads %d...\n", omp_get_max_threads());
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "No of Processors %d...\n", omp_get_num_procs());
omp_set_num_threads(omp_get_max_threads());
omp_set_dynamic(0);
start = omp_get_wtime();
#pragma omp parallel for private(x, tid) reduction(+:sum)
tid = omp_get_thread_num();
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "No. of Threads working %d \n", omp_get_num_threads());
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Thread %d working...\n", tid);
for (i=0; i < steps; i++) {
x = (i+0.5)*step;
sum += 4.0 / (1.0+x*x);
}
delta = omp_get_wtime() - start;
// Out of the parallel region, finialize computation
pi = step * sum;
//printf("PI = %.16g computed in %.4g seconds\n", pi, delta);
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "PI = %.16g computed in %.4g seconds\n", pi, delta);
return pi;
}
I am trying to explore OpenMP in Android. However, my code always runs
using 1 thread even if the max no of threads available is 6. I have tried
to set the no. of threads to 6 but it still runs on only 1. I have also
tried to set the environment variable to 6 but it still doesn't work. Can
anyone provide some insight as to why this is happening? Here is the code I
am using.
jdouble Java_edu_example_anative_myfirstnativeapp_MyNative_calcPipar(){
int i,j;
int tid;
double x;
double pi, sum = 0.0;
double start, delta;
step = 1.0/(double) steps;
sum = 0.0;
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Max Threads %d...\n", omp_get_max_threads());
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "No of Processors %d...\n", omp_get_num_procs());
omp_set_num_threads(omp_get_max_threads());
omp_set_dynamic(0);
start = omp_get_wtime();
#pragma omp parallel for private(x, tid) reduction(+:sum)
tid = omp_get_thread_num();
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "No. of Threads working %d \n", omp_get_num_threads());
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "Thread %d working...\n", tid);
for (i=0; i < steps; i++) {
x = (i+0.5)*step;
sum += 4.0 / (1.0+x*x);
}
delta = omp_get_wtime() - start;
// Out of the parallel region, finialize computation
pi = step * sum;
//printf("PI = %.16g computed in %.4g seconds\n", pi, delta);
__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, "PI = %.16g computed in %.4g seconds\n", pi, delta);
return pi;
}
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7c3fc447-1054-4f78-b077-848d5bb13da6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/7c3fc447-1054-4f78-b077-848d5bb13da6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.