i.MX6Q and OpenMP not work

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i.MX6Q and OpenMP not work

546 Views
ask_mobile
Contributor I

I try to run OpenMp on i.MX6Q, but on the test task I see that only one core works at a time, while the monitor shows the load of all cores.
Here is an example that shows that the program is executed sequentially and not in parallel.

From the debug output, it can be seen that the threads are created and launched at about the same time, but then they work sequentially.
What and how to do to run the threads simultaneously ???

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <sys/time.h>


int omp(const uint8_t * restrict a, uint8_t * restrict n, int len) {
uint32_t i;
struct timeval tv;

gettimeofday(&tv,0);
printf("Time:%d\n",tv.tv_usec);
#pragma omp parallel for num_threads(4)

for (i=1; i<len; i++) {
gettimeofday(&tv,0);
printf("Time:%d Thread %d, y=%d\n",tv.tv_usec,omp_get_thread_num(),i);
n[i] = (a[i] + a[i-1]) / 2.0;
}

gettimeofday(&tv,0);
printf("Time:%d\n",tv.tv_usec);
return 0;
}

int main(int argc, char *argv[]) {
uint8_t * a;
uint8_t * n;
int32_t i;
a = malloc( 24*24);
n = malloc( 24*24);
//for (i=0;i<100;i++)
omp(a,n,24);
return 0;
}

Here is the sorted output:

Time:675347
Time:676345 Thread 0, y=1
Time:676345 Thread 1, y=7
Time:676346 Thread 2, y=13
Time:676352 Thread 3, y=19

Time:676420 Thread 1, y=8
Time:676477 Thread 1, y=9
Time:676509 Thread 1, y=10
Time:676542 Thread 1, y=11
Time:676566 Thread 1, y=12
Time:676618 Thread 3, y=20
Time:676658 Thread 3, y=21
Time:676691 Thread 3, y=22
Time:676715 Thread 3, y=23
Time:676805 Thread 0, y=2
Time:676842 Thread 0, y=3
Time:676874 Thread 0, y=4
Time:676968 Thread 0, y=5
Time:677004 Thread 0, y=6
Time:677087 Thread 2, y=14
Time:677113 Thread 2, y=15
Time:677136 Thread 2, y=16
Time:677157 Thread 2, y=17
Time:677177 Thread 2, y=18
Time:677222

0 Kudos
1 Reply

454 Views
igorpadykov
NXP Employee
NXP Employee

Hi Ask2000

one can look at baremetal sdk "smp_primes" example showing

multiple CPU cores running in parallel, zip can be found on link

SMP Enable in IMX6 

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos