Skip to content

Commit

Permalink
1) Made it so that keys hashed are chosen at random from the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
richardklafter committed Oct 11, 2012
1 parent 6bc43d5 commit 7468d43
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions scallion/CLRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ static private int get_der_len(ulong val)

return len;
}

public class RandomList<T>
{
private System.Random _rnd = new System.Random();
private List<T> _list = new List<T>();
public void Push(T value)
{
_list.Add(value);
}
public T Pop()
{
if(_list.Count <= 0) return default(T);
T ret = _list[_rnd.Next(0, _list.Count)];
_list.Remove(ret);
return ret;
}
public int Count
{
get { return _list.Count; }
}
}

public class KernelInput
{
Expand Down Expand Up @@ -76,7 +97,7 @@ public KernelInput(int num_exps)
const uint EXP_MIN = 0x01010001;
const uint EXP_MAX = 0x7FFFFFFF;
public bool Abort = false;
private Queue<KernelInput> _kernelInput = new Queue<KernelInput>();
private RandomList<KernelInput> _kernelInput = new RandomList<KernelInput>();
private void CreateInput()
{
while (true)
Expand Down Expand Up @@ -171,7 +192,7 @@ private void CreateInput()
{
foreach (KernelInput i in inputs)
{
_kernelInput.Enqueue(i);
_kernelInput.Push(i);
}
}
continue;//skip the sleep cause we might be really low
Expand Down Expand Up @@ -303,7 +324,7 @@ public void Run(int deviceId, int workGroupSize, int workSize, int numThreadsCre
KernelInput input = null;
lock (_kernelInput)
{
if (_kernelInput.Count > 0) input = _kernelInput.Dequeue();
if (_kernelInput.Count > 0) input = _kernelInput.Pop();
}
if (input == null) //If we have run out of work sleep for a bit
{
Expand Down

0 comments on commit 7468d43

Please sign in to comment.