Discussion:
OpenMP in NDK always uses 1 thread
Joydeep Mitra
2017-12-01 18:42:24 UTC
Permalink
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;
}
--
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.
'Ryan Prichard' via android-ndk
2017-12-01 20:16:04 UTC
Permalink
The code didn't compile:
- LOG_TAG, step, and steps weren't declared.
- The #pragma omp needs to immediately precede the for loop. Move the "for
(i=0; i < steps; i++) {" line up.

Once I make those fixes, I see this output:

11-27 04:59:13.173 10356 10356 D test : Max Threads 8...
11-27 04:59:13.173 10356 10356 D test : No of Processors 8...
11-27 04:59:13.179 10356 10356 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10358 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10356 D test : Thread 0 working...
11-27 04:59:13.179 10356 10358 D test : Thread 2 working...
...
11-27 04:59:13.179 10356 10358 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10358 D test : Thread 2 working...
11-27 04:59:13.179 10356 10359 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10359 D test : Thread 3 working...
11-27 04:59:13.179 10356 10359 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10359 D test : Thread 3 working...
11-27 04:59:13.179 10356 10359 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10359 D test : Thread 3 working...
11-27 04:59:13.179 10356 10359 D test : No. of Threads working 8
11-27 04:59:13.179 10356 10359 D test : Thread 3 working...
...
11-27 04:59:13.194 10356 10361 D test : No. of Threads working 8
11-27 04:59:13.194 10356 10361 D test : Thread 5 working...
11-27 04:59:13.194 10356 10361 D test : No. of Threads working 8
11-27 04:59:13.194 10356 10361 D test : Thread 5 working...
11-27 04:59:13.197 10356 10356 D test : PI = 3.141600986923125 computed
in 0.02364 seconds

-Ryan
Post by Joydeep Mitra
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;
}
--
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
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
<https://groups.google.com/d/msgid/android-ndk/7c3fc447-1054-4f78-b077-848d5bb13da6%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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/CALgsJzki%2Bh%3D6tAJz9Reh5u_H0KmX-UZWtbJvPJcwHhfdsHLJ5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Kenneth Geisshirt
2017-12-02 16:00:05 UTC
Permalink
Which NDK version do you use? I think you need r15 and use clang as
compiler.

- Kenneth
Post by Joydeep Mitra
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;
}
--
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
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
<https://groups.google.com/d/msgid/android-ndk/7c3fc447-1054-4f78-b077-848d5bb13da6%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
Kenneth Geisshirt, M.Sc., Ph.D.
MajbÞl Allé 18, DK-2770 Kastrup, +45 60 62 71 82
--
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/CAFLzvuqPAbwt5-0J2rL9B05RkA8o4OO4RuxdL0OZ4uZvTeYOJg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Arthur Araújo
2017-12-26 19:24:09 UTC
Permalink
Hi,

Did you get it working? I'm having a similar problem trying to create
OpenMP threads in Android. I'm using Clang 3.8 on Visual Studio 2015
(Android NDK r11c). Basically, I got it all compiled and running on mobile,
but there is no forking going on, I always end up with one thread only.

Arthur

Em sexta-feira, 1 de dezembro de 2017 16:25:42 UTC-3, Joydeep Mitra
Post by Joydeep Mitra
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;
}
--
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/88b5a863-efd2-49ea-93e6-a41a10052491%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...