private unsafe void PopulateWorker(int threadId) { Native32.AffinitizeThreadRoundRobin((uint)threadId); Empty context; var success = inputArrays.TryTake(out Input[] inputArray); if (!success) { Console.WriteLine("No input array for {0}", threadId); return; } // Register thread with the store fht.StartSession(); Interlocked.Increment(ref numActiveThreads); // Process the batch of input data fixed(Input *input = inputArray) { for (long i = 0; i < numOps; i++) { fht.RMW(&((input + i)->adId), input + i, &context, i); if ((i + 1) % checkpointInterval == 0 && numActiveThreads == threadCount) { if (fht.TakeFullCheckpoint(out Guid token)) { tokens.Add(token); } } if (i % completePendingInterval == 0) { fht.CompletePending(false); } else if (i % refreshInterval == 0) { fht.Refresh(); } } } // Make sure operations are completed fht.CompletePending(true); // Deregister thread from FASTER fht.StopSession(); //Interlocked.Decrement(ref numActiveThreads); Console.WriteLine("Populate successful on thread {0}", threadId); }
public unsafe void Populate() { List <Guid> tokens = new List <Guid>(); Empty context; // Prepare the dataset var inputArray = new Input[numOps]; for (int i = 0; i < numOps; i++) { inputArray[i].adId.adId = i % numUniqueKeys; inputArray[i].numClicks.numClicks = 1; } // Register thread with FASTER fht.StartSession(); // Prpcess the batch of input data fixed(Input *input = inputArray) { for (int i = 0; i < numOps; i++) { fht.RMW(&((input + i)->adId), input + i, &context, i); if (i % checkpointInterval == 0) { if (fht.TakeFullCheckpoint(out Guid token)) { tokens.Add(token); } } if (i % completePendingInterval == 0) { fht.CompletePending(false); } else if (i % refreshInterval == 0) { fht.Refresh(); } } } // Make sure operations are completed fht.CompletePending(true); // Deregister thread from FASTER fht.StopSession(); Console.WriteLine("Populate successful"); foreach (var token in tokens) { Console.WriteLine(token); } Console.ReadLine(); }
private unsafe void PopulateWorker(int threadId) { Native32.AffinitizeThreadRoundRobin((uint)threadId); Empty context; var success = inputArrays.TryTake(out Input[] inputArray); if (!success) { Console.WriteLine("No input array for {0}", threadId); return; } // Register thread with the store fht.StartSession(); Interlocked.Increment(ref numActiveThreads); // Process the batch of input data var random = new Random(threadId + 1); threadNumOps[threadId] = (numOps / 2) + random.Next() % (numOps / 4); fixed(Input *input = inputArray) { for (long i = 0; i < threadNumOps[threadId]; i++) { fht.RMW(&((input + i)->adId), input + i, &context, i); if (i % completePendingInterval == 0) { fht.CompletePending(false); } else if (i % refreshInterval == 0) { fht.Refresh(); } } } // Make sure operations are completed fht.CompletePending(true); // Deregister thread from FASTER fht.StopSession(); //Interlocked.Decrement(ref numActiveThreads); Console.WriteLine("Populate successful on thread {0}", threadId); }
public unsafe void Populate() { Empty context; // Prepare the dataset var inputArray = new Input[numOps]; for (int i = 0; i < numOps; i++) { inputArray[i].adId.adId = i % numUniqueKeys; inputArray[i].numClicks.numClicks = 1; } // Register thread with FASTER fht.StartSession(); // Prpcess the batch of input data bool first = true; fixed(Input *input = inputArray) { for (int i = 0; i < numOps; i++) { fht.RMW(&((input + i)->adId), input + i, &context, i); if ((i + 1) % checkpointInterval == 0) { if (first) { while (!fht.TakeFullCheckpoint(out token)) { fht.Refresh(); } } else { while (!fht.TakeFullCheckpoint(out Guid nextToken)) { fht.Refresh(); } } first = false; } if (i % completePendingInterval == 0) { fht.CompletePending(false); } else if (i % refreshInterval == 0) { fht.Refresh(); } } } // Make sure operations are completed fht.CompletePending(true); // Deregister thread from FASTER fht.StopSession(); }
public unsafe void NativeInMemRMW1() { var nums = Enumerable.Range(0, 1000).ToArray(); var rnd = new Random(11); for (int i = 0; i < nums.Length; ++i) { int randomIndex = rnd.Next(nums.Length); int temp = nums[randomIndex]; nums[randomIndex] = nums[i]; nums[i] = temp; } for (int j = 0; j < nums.Length; ++j) { var i = nums[j]; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var input = new InputStruct { ifield1 = i, ifield2 = i + 1 }; fht.RMW(&key1, &input, null, 0); } for (int j = 0; j < nums.Length; ++j) { var i = nums[j]; var key1 = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; var input = new InputStruct { ifield1 = i, ifield2 = i + 1 }; fht.RMW(&key1, &input, null, 0); } KeyStruct key = default(KeyStruct); ValueStruct value = default(ValueStruct); OutputStruct output = default(OutputStruct); Status status = default(Status); for (int j = 0; j < nums.Length; ++j) { var i = nums[j]; key = new KeyStruct { kfield1 = i, kfield2 = i + 1 }; value = new ValueStruct { vfield1 = i, vfield2 = i + 1 }; status = fht.Read(&key, null, &output, null, 0); if (status == Status.PENDING) { fht.CompletePending(true); } else { Assert.IsTrue(status == Status.OK); } Assert.IsTrue(output.value.vfield1 == 2 * value.vfield1, "found " + output.value.vfield1 + ", expected " + 2 * value.vfield1); Assert.IsTrue(output.value.vfield2 == 2 * value.vfield2); } key = new KeyStruct { kfield1 = nums.Length, kfield2 = nums.Length + 1 }; status = fht.Read(&key, null, &output, null, 0); if (status == Status.PENDING) { fht.CompletePending(true); } else { Assert.IsTrue(status == Status.NOTFOUND); } }