Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int numberofSets = 3;
- int set1ElementCount = 5840;
- int set2ElementCount = 5840;
- int set3ElementCount = 2;
- int combinationsCount = 68211200; // = 5840 * 5840 * 2
- int dataCount = 64000;
- int[,] combinations = new int[combinationsCount, numberofSets];
- // combinations = generator.Generate(); // generate combinations
- /* generated format is:
- [0,0,0]
- [0,0,1]
- [1,0,0]
- ...
- [5839, 5839, 1]
- */
- //itterate combinations
- Parallel.For(0, combinationsCount, (idx, state) =>
- {
- int idx1 = combinations[idx, 0]; // a bit of hardcoding here since we have 3 sets of data
- int idx2 = combinations[idx, 1];
- int idx3 = combinations[idx, 3];
- // proccess data set for each combination
- for (int i = 0; i < dataCount; i++) {
- // do something
- }
- });
- // itterate set 1 in parallel
- Parallel.For(0, set1ElementCount, (idx1, state) =>
- {
- // itterate set 2
- for (int idx2 = 0; idx2 < set2ElementCount; idx2 ++)
- {
- // itterate set 3
- for (int idx3 = 0; idx3 < set3ElementCount; idx3 ++)
- {
- // proccess data set for each combination
- for (int i = 0; i < dataCount; i++)
- {
- // do something
- }
- }
- }
- });
- // itterate set 1
- for (int idx1 = 0; idx1 < set1ElementCount; idx1 ++)
- {
- // itterate set 2
- for (int idx2 = 0; idx2 < set2ElementCount; idx2 ++)
- {
- // itterate set 3
- for (int idx3 = 0; idx3 < set3ElementCount; idx3 ++)
- {
- // proccess data set for each combination
- for(int i = 0; i < dataCount; i++)
- {
- // do something
- }
- }
- }
- }
- var combinationsCount = combinations.Length;
- int coreCount = 4;
- int chuncSize = combinationsCount / coreCount;
- List<int[][]> chunked = new List<int[][]>();
- for (int i = 0; i < coreCount; i++)
- {
- int skip = i * chuncSize;
- int take = chuncSize;
- int diff = (length - skip) - take;
- if (diff < chuncSize)
- take = take + diff;
- var sub = combinations.Skip(skip).Take(take).ToArray();
- chunked.Add(sub);
- }
- // iterate chunks - each on a separate core
- Parallel.For(0, coreCount, new ParallelOptions() { MaxDegreeOfParallelism = coreCount }, (chunkIndex, state) =>
- {
- var chunk = chunked[chunkIndex];
- int chunkLength = chunk.Length;
- // iterate combinations per-chunk
- for (int idx = 0; idx < chunkLength; idx++)
- {
- // itterate data here
- }
- }
Add Comment
Please, Sign In to add comment