Guest User

Untitled

a guest
Mar 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. int numberofSets = 3;
  2.  
  3. int set1ElementCount = 5840;
  4. int set2ElementCount = 5840;
  5. int set3ElementCount = 2;
  6.  
  7. int combinationsCount = 68211200; // = 5840 * 5840 * 2
  8. int dataCount = 64000;
  9.  
  10. int[,] combinations = new int[combinationsCount, numberofSets];
  11. // combinations = generator.Generate(); // generate combinations
  12. /* generated format is:
  13. [0,0,0]
  14. [0,0,1]
  15. [1,0,0]
  16. ...
  17. [5839, 5839, 1]
  18. */
  19. //itterate combinations
  20. Parallel.For(0, combinationsCount, (idx, state) =>
  21. {
  22. int idx1 = combinations[idx, 0]; // a bit of hardcoding here since we have 3 sets of data
  23. int idx2 = combinations[idx, 1];
  24. int idx3 = combinations[idx, 3];
  25.  
  26. // proccess data set for each combination
  27. for (int i = 0; i < dataCount; i++) {
  28. // do something
  29. }
  30. });
  31.  
  32. // itterate set 1 in parallel
  33. Parallel.For(0, set1ElementCount, (idx1, state) =>
  34. {
  35. // itterate set 2
  36. for (int idx2 = 0; idx2 < set2ElementCount; idx2 ++)
  37. {
  38. // itterate set 3
  39. for (int idx3 = 0; idx3 < set3ElementCount; idx3 ++)
  40. {
  41. // proccess data set for each combination
  42. for (int i = 0; i < dataCount; i++)
  43. {
  44. // do something
  45. }
  46. }
  47. }
  48. });
  49.  
  50. // itterate set 1
  51. for (int idx1 = 0; idx1 < set1ElementCount; idx1 ++)
  52. {
  53. // itterate set 2
  54. for (int idx2 = 0; idx2 < set2ElementCount; idx2 ++)
  55. {
  56. // itterate set 3
  57. for (int idx3 = 0; idx3 < set3ElementCount; idx3 ++)
  58. {
  59. // proccess data set for each combination
  60. for(int i = 0; i < dataCount; i++)
  61. {
  62. // do something
  63. }
  64. }
  65. }
  66. }
  67.  
  68. var combinationsCount = combinations.Length;
  69. int coreCount = 4;
  70. int chuncSize = combinationsCount / coreCount;
  71. List<int[][]> chunked = new List<int[][]>();
  72. for (int i = 0; i < coreCount; i++)
  73. {
  74. int skip = i * chuncSize;
  75. int take = chuncSize;
  76.  
  77. int diff = (length - skip) - take;
  78. if (diff < chuncSize)
  79. take = take + diff;
  80.  
  81. var sub = combinations.Skip(skip).Take(take).ToArray();
  82.  
  83. chunked.Add(sub);
  84. }
  85.  
  86. // iterate chunks - each on a separate core
  87. Parallel.For(0, coreCount, new ParallelOptions() { MaxDegreeOfParallelism = coreCount }, (chunkIndex, state) =>
  88. {
  89. var chunk = chunked[chunkIndex];
  90. int chunkLength = chunk.Length;
  91.  
  92. // iterate combinations per-chunk
  93. for (int idx = 0; idx < chunkLength; idx++)
  94. {
  95. // itterate data here
  96. }
  97. }
Add Comment
Please, Sign In to add comment