Exemplo n.º 1
0
        public void ScheduleSimpleParallelFor()
        {
            NativeArray <int> a      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> b      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> result = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                a[i] = 100 + i;
                b[i] = 200 + i;
            }

            SimpleParallelFor job = new SimpleParallelFor()
            {
                a = a, b = b, result = result
            };

            job.a      = a;
            job.b      = b;
            job.result = result;

            JobHandle handle = job.Schedule(result.Length, 300);

            handle.Complete();

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                Assert.AreEqual(300 + i * 2, result[i]);
            }

            b.Dispose();
            result.Dispose();
        }
Exemplo n.º 2
0
        // The parameter variants are intended to check "a little more and less" than typical thread counts, to
        // confirm work ranges are assigned - at least correctly enough - so that each index is called once.
        public void ScheduleSimpleParallelFor([Values(1, 3, 4, 5, 7, 8, 9, 11, 12, 13, 15, 16, 17, 1000)] int arrayLen)
        {
            NativeArray <int> a      = new NativeArray <int>(arrayLen, Allocator.TempJob);
            NativeArray <int> b      = new NativeArray <int>(arrayLen, Allocator.TempJob);
            NativeArray <int> result = new NativeArray <int>(arrayLen, Allocator.TempJob);

            for (int i = 0; i < arrayLen; ++i)
            {
                a[i] = 100 + i;
                b[i] = 200 + i;
            }

            SimpleParallelFor job = new SimpleParallelFor()
            {
                a = a, b = b, result = result
            };

            job.a      = a;
            job.b      = b;
            job.result = result;

            JobHandle handle = job.Schedule(result.Length, 100);

            handle.Complete();

            for (int i = 0; i < arrayLen; ++i)
            {
                Assert.AreEqual(300 + i * 2, result[i]);
            }

            b.Dispose();
            result.Dispose();
        }
Exemplo n.º 3
0
        public void RunSimpleParallelFor()
        {
            didDispose = 0;
            NativeArray <int> a      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> b      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> result = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                a[i] = 100 + i;
                b[i] = 200 + i;
            }

            SimpleParallelFor job = new SimpleParallelFor()
            {
                a = a, b = b, result = result
            };

            job.a      = a;
            job.b      = b;
            job.result = result;

            JobHandle handle = job.Schedule(result.Length, 300);

            handle.Complete();

#if !UNITY_DOTSPLAYER
            // TODO: Understand / fix why the editor tests don't run quite the same code path.
            job.mDisposable.Dispose();
#endif
            Assert.AreEqual(didDispose, 1);

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                Assert.AreEqual(result[i], 300 + i * 2);
            }

            a.Dispose();
            b.Dispose();
            result.Dispose();
        }
Exemplo n.º 4
0
        public void RunSimpleParallelFor()
        {
            didDispose = 0;
            NativeArray <int> a      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> b      = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);
            NativeArray <int> result = new NativeArray <int>(SimpleParallelFor.N, Allocator.TempJob);

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                a[i] = 100 + i;
                b[i] = 200 + i;
            }

            SimpleParallelFor job = new SimpleParallelFor()
            {
                a = a, b = b, result = result
            };

            job.a      = a;
            job.b      = b;
            job.result = result;

            JobHandle handle = job.Schedule(result.Length, 300);

            handle.Complete();

#if NET_DOTS
            Assert.AreEqual(didDispose, 1);
#endif

            for (int i = 0; i < SimpleParallelFor.N; ++i)
            {
                Assert.AreEqual(result[i], 300 + i * 2);
            }

            a.Dispose();
            b.Dispose();
            result.Dispose();
        }