Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathProgram.cs
More file actions
199 lines (154 loc) · 9.67 KB
/
Copy pathProgram.cs
File metadata and controls
199 lines (154 loc) · 9.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
using System;
using System.Collections.Generic;
using System.Linq;
using HPCsharp;
namespace HPCsharpExamples
{
partial class Program
{
static void Main(string[] args)
{
#region Simple example of serial and parallel sorting of integer arrays
Console.WriteLine("Simple example of serial and parallel sorting of integer arrays");
uint[] ArrayOne = { 21, 43, 16, 5, 54, 3 };
uint[] ArrayTwo = { 21, 43, 16, 5, 54, 3 };
uint[] ArrayThree = { 21, 43, 16, 5, 54, 3 };
uint[] ArrayFour = { 21, 43, 16, 5, 54, 3 };
uint[] ArrayFive = { 21, 43, 16, 5, 54, 3 };
uint[] ArraySix = { 21, 43, 16, 5, 54, 3 };
Array.Sort(ArrayOne); // C# standard in-place Sort
ArrayTwo.SortMergeInPlace(); // HPCsharp in-place Merge Sort (serial)
ArrayThree.SortMergeInPlaceAdaptivePar(); // HPCsharp in-place Merge Sort (parallel)
uint[] sortedArrayFour = ArrayFour.SortRadix(); // HPCsharp Radix Sort (not in-place, serial)
uint[] sortedArrayFive = ArrayFive.SortMerge(); // HPCsharp Merge Sort (not in-place, serial)
uint[] sortedArraySix = ArraySix.SortMergePar(); // HPCsharp Merge Sort (not in-place, parallel)
bool equalSortedArraysOneAndTwo = ArrayOne.SequenceEqual(ArrayTwo);
bool equalSortedArraysOneAndThree = ArrayOne.SequenceEqual(ArrayThree);
bool equalSortedArraysOneAndFour = ArrayOne.SequenceEqual(ArrayFour);
bool equalSortedArraysOneAndFive = ArrayOne.SequenceEqual(ArrayFive);
bool equalSortedArraysOneAndSix = ArrayOne.SequenceEqual(ArraySix);
if (equalSortedArraysOneAndTwo && equalSortedArraysOneAndThree && equalSortedArraysOneAndFour &&
equalSortedArraysOneAndFive && equalSortedArraysOneAndSix)
Console.WriteLine("Sorting for variety of Merge Sort(s) results are equal");
else
Console.WriteLine("Sorting for variety of Merge Sort(s) results are not equal!");
Console.WriteLine();
#endregion
#region More examples of sorting usage
SortingUsageExamples.SortingBasicExamples();
#endregion
#region Examples of sorting of user defined classes
Console.WriteLine("Examples of sorting of user defined classes");
SortOfUserDefinedClass.SimpleInPlaceExample();
SortOfUserDefinedClass.SimpleNotInPlaceExample();
#endregion
//if (!StabilityTest.SortingArrayOfUserDefinedClass(true, true))
// return;
#region Performance comparison of Merge Sort
Console.WriteLine();
Console.WriteLine("Performance comparison of Merge Sort");
SortMeasureArraySpeedup(false, false, false); // Measure Array Serial Sorting speedup for Serial Merge Sort
SortMeasureArraySpeedup(true, false, false); // Measure Array Serial Sorting speedup for Parallel Merge Sort
SortMeasureArraySpeedup(false, true, false); // Measure Linq Serial Sorting speedup for Serial Merge Sort
SortMeasureArraySpeedup(true, true, false); // Measure Linq Parallel Sorting speedup for Parallel Merge Sort
#endregion
#region Performance comparison of Serial Radix Sort for Array
Console.WriteLine();
Console.WriteLine("Performance comparison of Serial and Parallel Radix Sort for Array");
SortMeasureArraySpeedup(false, false, true); // Measure Array Serial Sorting speedup for Serial Radix Sort
SortMeasureArraySpeedup(false, true, true); // Measure Linq Serial Sorting speedup for Serial Radix Sort
SortMeasureArraySpeedup(true, true, true); // Measure Linq Parallel Sorting speedup for Serial Radix Sort
#endregion
#region Performance comparison of Serial Radix Sort for List
Console.WriteLine();
Console.WriteLine("Performance comparison of Serial Radix Sort for List");
SortMeasureListSpeedup(); // Measure List.Sort speedup for Serial Radix Sort
#endregion
#region Performance comparison of Merge Sort of User Defined Class
Console.WriteLine();
Console.WriteLine("Performance comparison of Merge Sort of User Defined Class");
SortMeasureArrayOfUserDefinedClassSpeedup(false, false, false); // Measure Array Serial Sorting speedup for Serial Merge Sort
SortMeasureArrayOfUserDefinedClassSpeedup(true, false, false); // Measure Array Serial Sorting speedup for Parallel Merge Sort
SortMeasureArrayOfUserDefinedClassSpeedup(false, true, false); // Measure Linq Serial Sorting speedup for Serial Merge Sort
SortMeasureArrayOfUserDefinedClassSpeedup(true, true, false); // Measure Linq Parallel Sorting speedup for Parallel Merge Sort
#endregion
#region Performance comparison of Serial Radix Sort for Array of User Defined Class
Console.WriteLine();
Console.WriteLine("Performance comparison of Serial Radix Sort for Array of User Defined Class");
SortMeasureArrayOfUserDefinedClassSpeedup(false, false, true); // Measure Array Serial Sorting speedup for Serial Radix Sort
SortMeasureArrayOfUserDefinedClassSpeedup(false, true, true); // Measure Linq Serial Sorting speedup for Serial Radix Sort
SortMeasureArrayOfUserDefinedClassSpeedup(true, true, true); // Measure Linq Parallel Sorting speedup for Serial Radix Sort
#endregion
#region Example of sequence equality checking - serial and parallel
Console.WriteLine();
Console.WriteLine("Example of sequence equality checking - serial and parallel");
int[] arrayOne = { 21, 43, 16, 5, 4, -3 };
int[] arrayTwo = { 21, 43, 16, 5, 4, -3 };
bool equalLinq = arrayOne.SequenceEqual( arrayTwo); // Linq SequenceEqual()
bool equalHpc = arrayOne.SequenceEqualHpc(arrayTwo); // HPCsharp SequenceEqual()
Console.WriteLine("Check array equality: {0} {1}", equalLinq, equalHpc);
// Check array inequality
int[] arrayThree = { 21, 43, 16, 3, 4, -3 }; // one element is different
equalLinq = arrayOne.SequenceEqual( arrayThree); // Linq SequenceEqual()
equalHpc = arrayOne.SequenceEqualHpc(arrayThree); // HPCsharp SequenceEqual()
Console.WriteLine("Check array inequality: {0} {1}", equalLinq, equalHpc);
// Check List equality
List<int> listOne = new List<int>() { 21, 43, 16, 5, 4, -3 };
List<int> listTwo = new List<int>() { 21, 43, 16, 5, 4, -3 };
equalLinq = listOne.SequenceEqual( listTwo); // Linq SequenceEqual()
equalHpc = listOne.SequenceEqualHpc(listTwo); // HPCsharp SequenceEqual()
Console.WriteLine("Check list equality: {0} {1}", equalLinq, equalHpc);
// Check List inequality
List<int> listThree = new List<int>() { 21, 43, 16, 3, 4, -3 }; // one element is different
equalLinq = listOne.SequenceEqual( listThree); // Linq SequenceEqual()
equalHpc = listOne.SequenceEqualHpc(listThree); // HPCsharp SequenceEqual()
Console.WriteLine("Check list inequality: {0} {1}", equalLinq, equalHpc);
#endregion
#region Example of sequence Min/Max - serial and parallel
Console.WriteLine();
Console.WriteLine("Example of sequence Min/Max - serial and parallel");
// Array Min
int minLinq = arrayOne.Min();
int minHpc = arrayOne.MinHpc();
Console.WriteLine("Check array Min: {0} {1}", minLinq, minHpc);
// List Min
minLinq = listOne.Min();
minHpc = listOne.MinHpc();
Console.WriteLine("Check List Min: {0} {1}", minLinq, minHpc);
// Array Max
int maxLinq = arrayOne.Max();
int maxHpc = arrayOne.MaxHpc();
Console.WriteLine("Check array Max: {0} {1}", maxLinq, maxHpc);
// List Min
maxLinq = listOne.Max();
maxHpc = listOne.MaxHpc();
Console.WriteLine("Check List Max: {0} {1}", maxLinq, maxHpc);
#endregion
#region Performance comparison of sequence equality and Min/Max - serial and parallel
Console.WriteLine();
Console.WriteLine("Performance comparison of sequence equality and Min/Max - serial and parallel");
// Measure array.SequenceEqual speedup
EqualMeasureArraySpeedup();
// Measure List.SequenceEqual speedup
EqualMeasureListSpeedup();
// Measure array.Min speedup
MinMeasureArraySpeedup();
// Measure List.Min speedup
MinMeasureListSpeedup();
// Measure array.Max speedup
MaxMeasureArraySpeedup();
// Measure List.Max speedup
MaxMeasureListSpeedup();
#endregion
#region Standard C# .Sum() problem examples
SumExamples.SumProblems();
#endregion
#region HPCsharp improved .Sum() examples
SumExamples.SumHPCsharpExamples();
#endregion
#region HPCsharp .Sum() performance speedup
SumMeasureArraySpeedup();
#endregion
}
}
}
You can’t perform that action at this time.
