void StartJobParallelFor() { NativeArray <float> a = new NativeArray <float>(2, Allocator.TempJob); NativeArray <float> b = new NativeArray <float>(2, Allocator.TempJob); NativeArray <float> result = new NativeArray <float>(2, Allocator.TempJob); a[0] = 1.1f; b[0] = 2.2f; a[1] = 3.3f; b[1] = 4.4f; MyParallelJob jobData = new MyParallelJob(); jobData.a = a; jobData.b = b; jobData.result = result; // Schedule the job with one Execute per index in the results array and only 1 item per processing batch JobHandle handle = jobData.Schedule(result.Length, 1); // Wait for the job to complete handle.Complete(); Debug.Log(result[0] + " " + result[1]); // Free the memory allocated by the arrays a.Dispose(); b.Dispose(); result.Dispose(); }
public static byte[] EndianSwap(byte[] inputBytes) { NativeArray <byte> a = new NativeArray <byte>(inputBytes.Length, Allocator.TempJob); NativeArray <byte> result = new NativeArray <byte>(inputBytes.Length, Allocator.TempJob); a.CopyFrom(inputBytes); MyParallelJob jobData = new MyParallelJob(); jobData.a = a; jobData.result = result; // Schedule the job with one Execute per index in the results array and only 1 item per processing batch JobHandle handle = jobData.Schedule(result.Length, 1); // Wait for the job to complete handle.Complete(); result.CopyTo(inputBytes); a.Dispose(); result.Dispose(); return(inputBytes); }
// Start is called before the first frame update void Start() { NativeArray <byte> a = new NativeArray <byte>(16, Allocator.TempJob); // NativeArray<float> b = new NativeArray<float>(2, Allocator.TempJob); NativeArray <byte> result = new NativeArray <byte>(16, Allocator.TempJob); for (int i = 0; i < 16; i++) { a[i] = (byte)('a' + i); } MyParallelJob jobData = new MyParallelJob(); jobData.a = a; jobData.result = result; // Schedule the job with one Execute per index in the results array and only 1 item per processing batch JobHandle handle = jobData.Schedule(result.Length, 1); // Wait for the job to complete handle.Complete(); Debug.Log("done"); foreach (char x in result) { Debug.Log(x); } // Free the memory allocated by the arrays a.Dispose(); result.Dispose(); }
private void ParallelCalc() { // record start time float startTime = Time.realtimeSinceStartup; var startTimea = DateTime.Now; NativeArray <float> a = new NativeArray <float>(calcSize, Allocator.TempJob); NativeArray <float> b = new NativeArray <float>(calcSize, Allocator.TempJob); NativeArray <float> result = new NativeArray <float>(calcSize, Allocator.TempJob); float startTime1 = Time.realtimeSinceStartup; var startTime1a = DateTime.Now; for (int i = 0; i < calcSize; i++) { a[i] = 0.005f * i; b[i] = 0.007f * i; } MyParallelJob jobData = new MyParallelJob(); jobData.a = a; jobData.b = b; jobData.result = result; // Schedule the job with one Execute per index in the results array and only 1 item per processing batch JobHandle handle = jobData.Schedule(result.Length, 100); // Wait for the job to complete handle.Complete(); // record end time float endTime = Time.realtimeSinceStartup; var endTimea = DateTime.Now;; //Debug.Log("TotalCount:" + result.Length); float temp = result[calcSize - 1]; Debug.Log("The last Value:" + temp); Debug.Log("TotalCount:" + result.Length + ",Parallel Use Time:" + (endTime - startTime) + ",Init Use Time:" + (startTime1 - startTime)); text.text += "ParallelCalc " + (endTime - startTime) + " "; Debug.Log("TotalCount:" + result.Length + ",Parallel Use Time:" + (endTimea - startTimea).TotalMilliseconds + ",Init Use Time:" + (startTime1a - startTimea).TotalMilliseconds); // Free the memory allocated by the arrays a.Dispose(); b.Dispose(); result.Dispose(); }