
Originally Posted by
DiamonDogX
I am aware that to execute something in a separate thread, one can simply extend QThread, implement run(), and write the pertinent code in the run method. But is there a way to execute an arbitrary block of code in a separate thread w/o having to create a whole new class? For example, maybe when I click a button I want a task to be executed in a separate thread, etc. Thanks.
Use OpenMP
#pragma omp parallel default(none) shared(n,a,b,c,d) private(i)
{
#pragma omp for nowait
for (i=0; i<n-1; i++) b[i] = (a[i] + a[i+1])/2;
#pragma omp for nowait
for ( i=0; i<n; i++ ) d[i] = 1./c[i];
} /* -- End of parallel region -- */
#pragma omp parallel default(none) shared(n,a,b,c,d) private(i)
{
#pragma omp for nowait
for (i=0; i<n-1; i++) b[i] = (a[i] + a[i+1])/2;
#pragma omp for nowait
for ( i=0; i<n; i++ ) d[i] = 1./c[i];
} /* -- End of parallel region -- */
To copy to clipboard, switch view to plain text mode
Or google search for QtConcurrent
Bookmarks