void MakeAndFind1() { kd1 = new KDTreeStruct(); kd1.MakeFromPoints(points_native); float rTot = 0; for (int i = 0; i < queries.Length; i++) { int id = kd1.FindNearest2(queries[i]); rTot = rTot + (queries[i] - points_native[id]).magnitude; } Debug.Log("Native array single threaded " + rTot); }
void MakeAndFind2() { kd2 = new KDTreeStruct(); kd2.MakeFromPoints(points_native); float rTot = 0; for (int i = 0; i < queries.Length; i++) { int id = kd2.FindNearest2(queries[i]); float3 relative = queries[i] - points_native[id]; rTot = rTot + math.sqrt(math.dot(relative, relative)); } Debug.Log("Native array jobified " + rTot); }
public void Execute(int i) { answers_job[i] = kd_job.FindNearest2(queries_job[i]); }
void Update() { // rTot here is the total of lengths between all query points and their nearest neighbours // rTot is a good controlling parameter to estimate if kdtree works correctly float rTot = 0; if (imode == 0) { for (int i = 0; i < queries.Length; i++) { int j = kd0.FindNearest(queries[i]); rTot = rTot + (queries[i] - points[j]).magnitude; } } else if (imode == 1) { for (int i = 0; i < queries.Length; i++) { int j = kd1.FindNearest2(queries[i]); rTot = rTot + (queries[i] - points_native[j]).magnitude; } } else if (imode == 2) { int processorCount = System.Environment.ProcessorCount; var job = new KdSearchJob() { kd_job = kd2, points_job = points_native, queries_job = queries, answers_job = answers }; JobHandle jobHandle = job.Schedule(queries.Length, processorCount); jobHandle.Complete(); for (int i = 0; i < answers.Length; i++) { int j = answers[i]; rTot = rTot + (queries[i] - points_native[j]).magnitude; } } if (printTotalSizeOnUpdate) { Debug.Log(rTot); } if (Input.GetKeyDown(KeyCode.A)) { imode = 0; Debug.Log("running with regular arrays"); } else if (Input.GetKeyDown(KeyCode.B)) { imode = 1; Debug.Log("running with native arrays"); } else if (Input.GetKeyDown(KeyCode.C)) { imode = 2; Debug.Log("running jobified"); } }