Cuda Programming

Im reading a table from file that may have rows - 1 to 100,000.As part of my code ,i have to compare a 1d array values inside kernel. my array is dynamic whose size may vary from 1 to 100,000. I have to group them with similar values in a 2d array(output that has row identifiers say for 1000 rows 0-999) . How to do this in a optimized way since i was not satisfied with my coding