c - Merge two sorted arrays with OpenCL -


i have c code merge 2 sorted arrays:

void merge(int m, int n, int a[], int b[], int c[]) {   int i, j, k;   = 0;   j = 0;   k = 0;   while (i < m && j < n) {         if (a[i] <= b[j]) {               c[k] = a[i];               i++;         } else {               c[k] = b[j];               j++;         }         k++;   }   if (i < m) {         (int p = i; p < m; p++) {               c[k] = a[p];               k++;         }   } else {         (int p = j; p < n; p++) {               c[k] = b[p];               k++;         }   } } 

i want put merge part opencl kernel, best way this? or best way merge 2 sorted arrays opencl?

if arrays' lengths same power of two, can bitonic sorting. start final butterfly step (last block of blue/brown diagram in wiki link), , saturate gpu while getting out of memory speed of device. can pad arrays if close power of two. have sorted lists of several million (eg 2^20 .. 2^24) entries method. see: 'bitonic sorter' wiki

if have arbitrary number of elements in each array, may not worth transfer time when dealing 2 lists sorted. because comparing 2 values @ time, , moving 1 of them result list. terrible use of gpu, because single-threaded. optimization might load first 4-8kb each of source arrays local memory, write sorted block local memory well. still use 1 compute unit of entire gpu, memory speeds great. again, not worth trouble. cpu l1 , l2 data cache , superior clock speed should outperform gpu when merging arbitrary length, sorted arrays.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -