private static void RunSelectManyTest2Core(int outerSize, int innerSize) { string methodFailed = string.Format("RunSelectManyTest2(outerSize = {0}, innerSize = {1}) - sync/ no pipeline: FAILED. ", outerSize, innerSize); int[] left = new int[outerSize]; int[] right = new int[innerSize]; for (int i = 0; i < left.Length; i++) { left[i] = i; } for (int i = 0; i < right.Length; i++) { right[i] = i * 8; } //Assert.True(false, string.Format(" > Invoking SelectMany of {0} outer elems with {1} inner elems", left.Length, right.Length)); ParallelQuery <int> results = left.AsParallel().AsOrdered().SelectMany <int, int, int>(x => right.AsParallel(), delegate(int x, int y) { return(x + y); }); List <int> r = results.ToList <int>(); // Just validate the count. int cnt = 0; foreach (int p in r) { cnt++; } int expect = outerSize * innerSize; if (cnt != expect) { Assert.True(false, string.Format(methodFailed + " > Saw expected count? Saw = {0}, expect = {1}: FAILED.", cnt, expect)); } }
private static void RunSelectTest2(int dataSize) { string methodFailed = string.Format("RunSelectTest2(dataSize = {0}) - NO pipelining: FAILED. ", dataSize); int[] data = new int[dataSize]; for (int i = 0; i < data.Length; i++) { data[i] = i; } // Select the square. We will validate it during results. ParallelQuery <Pair <int, int> > q = data.AsParallel().Select <int, Pair <int, int> >( delegate(int x) { return(new Pair <int, int>(x, x * x)); }); int cnt = 0; List <Pair <int, int> > r = q.ToList <Pair <int, int> >(); foreach (Pair <int, int> p in r) { if (p.Second != p.First * p.First) { Assert.True(false, string.Format(methodFailed + " > **Failure: {0} is not the square of {1} ({2})", p.Second, p.First, p.First * p.First)); // plz } cnt++; } if (cnt != dataSize) { Assert.True(false, string.Format(methodFailed + " > Saw expected count? Saw = {0}, expect = {1}: FAILED", cnt, dataSize)); } }
private static void RunWhereTest2(int dataSize) { string methodFailed = string.Format("RunWhereTest2(dataSize = {0}) - async/pipeline: FAILED. ", dataSize); int[] data = new int[dataSize]; for (int i = 0; i < data.Length; i++) { data[i] = i; } // Filter out odd elements. ParallelQuery <int> q = data.AsParallel().Where <int>( delegate(int x) { return((x % 2) == 0); }); int cnt = 0; List <int> r = q.ToList <int>(); foreach (int p in r) { if ((p % 2) != 0) { Assert.True(false, string.Format(methodFailed + " > **Failure: {0} is odd, shouldn't be present", p)); } cnt++; } bool passed = (cnt == ((dataSize + 1) / 2)); if (!passed) { Assert.True(false, string.Format(methodFailed + " > Saw expected count? Saw = {0}, expect = {1}: {2}", cnt, ((dataSize + 1) / 2), passed)); } }
private static bool RunJoinTest1(int leftSize, int rightSize, int loops) { TestHarness.TestLog("RunJoinTest1({0}, {1}, {2})", leftSize, rightSize, loops); int[] left = new int[leftSize]; int[] right = new int[rightSize]; for (int i = 0; i < left.Length; i++) { left[i] = i; } for (int i = 0; i < right.Length; i++) { right[i] = i * right.Length; } Func <int, int> identityKeySelector = delegate(int x) { return(x); }; IEnumerable <Pair> seqQuery = Enumerable.Join <int, int, int, Pair>( left, right, identityKeySelector, identityKeySelector, delegate(int x, int y) { return(new Pair(x, y)); }); ParallelQuery <Pair> parQuery = left.AsParallel().Join <int, int, int, Pair>( right.AsParallel(), identityKeySelector, identityKeySelector, delegate(int x, int y) { return(new Pair(x, y)); }); PerfHelpers.DrivePerfComparison( delegate { Enumerable.ToList(seqQuery); }, delegate { parQuery.ToList(); }, loops); return(true); }
// // Uses an element's index to calculate an output value. If order preservation isn't // working, this would PROBABLY fail. Unfortunately, this isn't deterministic. But choosing // larger input sizes increases the probability that it will. // private static void RunIndexedWhereTest2(int dataSize) { string methodFailed = string.Format("RunIndexedWhereTest2(dataSize = {0}) - not pipelined: FAILED. ", dataSize); int[] data = new int[dataSize]; for (int i = 0; i < data.Length; i++) { data[i] = i; } // Filter out elements where index isn't equal to the value (shouldn't filter any!). ParallelQuery <int> q = data.AsParallel().AsOrdered().Where <int>( delegate(int x, int idx) { return(x == idx); }); int cnt = 0; List <int> r = q.ToList <int>(); foreach (int p in r) { if (p != cnt) { Assert.True(false, string.Format(methodFailed + " > **Failure: results not increasing in index order (expect {0}, saw {1})", cnt, p)); } cnt++; } if (cnt != dataSize) { Assert.True(false, string.Format(methodFailed + " > Saw expected count? Saw = {0}, expect = {1}: FAILED.", cnt, dataSize)); } }
private static bool RunJoinTest_ForProfile(int leftSize, int rightSize, int loops) { int[] left = new int[leftSize]; int[] right = new int[rightSize]; for (int i = 0; i < left.Length; i++) { left[i] = i; } for (int i = 0; i < right.Length; i++) { right[i] = i * right.Length; } Func <int, int> identityKeySelector = delegate(int x) { return(x); }; ParallelQuery <Pair> par = left.AsParallel().Join <int, int, int, Pair>( right.AsParallel(), identityKeySelector, identityKeySelector, delegate(int x, int y) { return(new Pair(x, y)); }); for (int j = 0; j < loops; j++) { Console.WriteLine(j); List <Pair> pp = par.ToList <Pair>(); } return(true); }
public static void ToList(Labeled <ParallelQuery <int> > labeled, int count) { ParallelQuery <int> query = labeled.Item; int seen = 0; Assert.All(query.ToList(), x => Assert.Equal(seen++, x)); Assert.Equal(count, seen); }
public static void ToList_Unordered(Labeled <ParallelQuery <int> > labeled, int count) { ParallelQuery <int> query = labeled.Item; IntegerRangeSet seen = new IntegerRangeSet(0, count); Assert.All(query.ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public static void Distinct_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart * 2, DefaultSize * 2, source.Item).Select(x => x / 2).Distinct(); Assert.All(query.ToList(), x => seen.Add((int)x)); seen.AssertComplete(); }
public List <WordHistoryModel> QueryAllOrderByIDDescending() { TableQuery <WordHistoryModel> t = Connection.Table <WordHistoryModel>(); ParallelQuery <WordHistoryModel> q = from s in t.AsParallel() orderby s.ID descending select s; return(q.ToList()); }
public List <WordHistoryModel> QueryByTaskID(Guid taskID) { TableQuery <WordHistoryModel> t = Connection.Table <WordHistoryModel>(); ParallelQuery <WordHistoryModel> q = from s in t.AsParallel() orderby s.ID descending select s; return(q.ToList()); }
public static void Intersect_Unordered_NotPipelined(Labeled <Operation> operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart - DefaultSize / 2, DefaultSize + DefaultSize / 2, DefaultSource) .Intersect(operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, DefaultSource)); Assert.All(query.ToList(), x => seen.Add((int)x)); seen.AssertComplete(); }
public WordNoteModel Query(string _word, int _notebookid) { TableQuery <WordNoteModel> t = Connection.Table <WordNoteModel>(); ParallelQuery <WordNoteModel> q = from s in t.AsParallel() where s.Word == _word & s.WordNoteBookID == _notebookid select s; return(q.ToList()[0]); }
public Pos_OfflineSource1 QueryPos(int _pos_id) { TableQuery <Pos_OfflineSource1> t = Connection.Table <Pos_OfflineSource1>(); ParallelQuery <Pos_OfflineSource1> q = from s in t.AsParallel() where s.ID == _pos_id select s; return(q.ToList()[0]); }
public int FindWordID(string _word) { TableQuery <Word> t = Connection.Table <Word>(); ParallelQuery <Word> q = from s in t.AsParallel() where s.Spelling == _word select s; return(q.ToList()[0].ID); }
public static void Zip_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(0, DefaultSize, source.Item) .Zip(operation.Item(DefaultStart, DefaultSize, source.Item), (x, y) => y); Assert.All(query.ToList(), x => seen.Add(x)); seen.AssertComplete(); }
public List <Mean_OfflineSource1> QueryMean(int _word_id) { TableQuery <Mean_OfflineSource1> t = Connection.Table <Mean_OfflineSource1>(); ParallelQuery <Mean_OfflineSource1> q = from s in t.AsParallel() where s.wordID == _word_id select s; return(q.ToList()); }
public WordNoteBookModel QueryByID(int ID) { TableQuery <WordNoteBookModel> t = Connection.Table <WordNoteBookModel>(); ParallelQuery <WordNoteBookModel> q = from s in t.AsParallel() where s.ID == ID select s; return(q.ToList()[0]); }
public static void Except_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <int> query = operation.Item(DefaultStart, DefaultSize + DefaultSize / 2, source.Item) .Except(operation.Item(DefaultStart + DefaultSize, DefaultSize, source.Item)); Assert.All(query.ToList(), x => seen.Add((int)x)); seen.AssertComplete(); }
public List <DefinitionStroage> QueryDefinitions(int _entryid) { TableQuery <DefinitionStroage> t = Connection.Table <DefinitionStroage>(); ParallelQuery <DefinitionStroage> q = from s in t.AsParallel() where s.Entry_ID == _entryid select s; return(q.ToList()); }
public List <WordNoteBookModel> Query() { TableQuery <WordNoteBookModel> t = Connection.Table <WordNoteBookModel>(); ParallelQuery <WordNoteBookModel> q = from s in t.AsParallel() orderby s.ID descending select s; return(q.ToList()); }
public List <MeanStorage> QueryMeans(Guid _definition_id) { TableQuery <MeanStorage> t = Connection.Table <MeanStorage>(); ParallelQuery <MeanStorage> q = from s in t.AsParallel() where s.Definition_ID == _definition_id select s; return(q.ToList()); }
public List <PartOfSpeechStorage> QueryPartOfSpeech(int _entry_id) { TableQuery <PartOfSpeechStorage> t = Connection.Table <PartOfSpeechStorage>(); ParallelQuery <PartOfSpeechStorage> q = from s in t.AsParallel() where s.Entry_ID == _entry_id select s; return(q.ToList()); }
public WordsStorageModel QueryEntry(int _word_id, int _dictionarysource_id) { TableQuery <WordsStorageModel> t = Connection.Table <WordsStorageModel>(); ParallelQuery <WordsStorageModel> q = from s in t.AsParallel() where s.Word_ID == _word_id & s.DictionarySource_ID == _dictionarysource_id select s; return(q.ToList()[0]); }
public int FindEntryID(string _word, int _dictionarysource_id) { TableQuery <WordsStorageModel> t = Connection.Table <WordsStorageModel>(); ParallelQuery <WordsStorageModel> q = from s in t.AsParallel() where s.Word == _word & s.DictionarySource_ID == _dictionarysource_id select s; return(q.ToList()[0].ID); }
public Words_OfflineSource1 QueryWord(string _word) { TableQuery <Words_OfflineSource1> t = Connection.Table <Words_OfflineSource1>(); ParallelQuery <Words_OfflineSource1> q = from s in t.AsParallel() where s.word == _word select s; var l = q.ToList(); return(l.Count > 0 ? l[0] : null); }
public List <WordNoteModel> QueryByNoteBookID(int _wordNoteBookID) { TableQuery <WordNoteModel> t = Connection.Table <WordNoteModel>(); ParallelQuery <WordNoteModel> q = from s in t.AsParallel() where s.WordNoteBookID == _wordNoteBookID orderby s.OrderedIndex ascending select s; return(q.ToList()); }
public WordHistoryModel QueryByID(int ID) { TableQuery <WordHistoryModel> t = Connection.Table <WordHistoryModel>(); ParallelQuery <WordHistoryModel> q = from s in t.AsParallel() where s.ID == ID select s; var l = q.ToList(); return(l.Count > 0 ? l[0] : null); }
public static void Join_Unordered_NotPipelined(LabeledOperation source, LabeledOperation operation) { IntegerRangeSet seen = new IntegerRangeSet(DefaultStart, DefaultSize); ParallelQuery <KeyValuePair <int, int> > query = operation.Item(DefaultStart / GroupFactor, DefaultSize / GroupFactor, source.Item) .Join(operation.Item(DefaultStart, DefaultSize, source.Item), x => x, y => y / GroupFactor, (x, y) => new KeyValuePair <int, int>(x, y)); foreach (KeyValuePair <int, int> p in query.ToList()) { Assert.Equal(p.Key, p.Value / GroupFactor); seen.Add(p.Value); } seen.AssertComplete(); }
public int Count() { try { TableQuery <WordNoteBookModel> t = Connection.Table <WordNoteBookModel>(); ParallelQuery <WordNoteBookModel> q = from s in t.AsParallel() select s; return(q.ToList().Count); } catch { return(0); } }