private void DoExample() { NativeArray <float> resultArray = new NativeArray <float>(1, Allocator.TempJob); SampleJob job1 = new SampleJob() { a = 100, result = resultArray, }; AnotherJob job2 = new AnotherJob() { result = resultArray, }; var handle = job1.Schedule(); handle.Complete(); job2.Schedule().Complete(); var value = job1.result[0]; Debug.Log($"result : {value}"); Debug.Log($"job.a : {job1.a}"); resultArray.Dispose(); }
public ScheduledJobRegistry(DateTime appointment) { //Removed the following line and replaced with next two lines //Schedule<SampleJob>().ToRunOnceIn(5).Seconds(); IJob job = new SampleJob(); JobManager.AddJob(job, s => s.ToRunOnceIn(5).Seconds()); }
/// <summary> /// Returns a list of poisson disc sampled points for a given area and density /// </summary> /// <param name="width">Width of the sampling area</param> /// <param name="height">Height of the sampling area</param> /// <param name="minimumRadius">The minimum distance required between each sampled point</param> /// <param name="seed">The random seed used to initialize the algorithm state</param> /// <param name="samplingResolution">The number of potential points sampled around every valid point</param> /// <param name="allocator">The allocator to use for the samples container</param> /// <returns>The list of generated poisson points</returns> public static NativeList <float2> GenerateSamples( float width, float height, float minimumRadius, uint seed = 12345, int samplingResolution = k_DefaultSamplingResolution, Allocator allocator = Allocator.TempJob) { if (width < 0) { throw new ArgumentException($"Width {width} cannot be negative"); } if (height < 0) { throw new ArgumentException($"Height {height} cannot be negative"); } if (minimumRadius < 0) { throw new ArgumentException($"MinimumRadius {minimumRadius} cannot be negative"); } if (seed == 0) { throw new ArgumentException("Random seed cannot be 0"); } if (samplingResolution <= 0) { throw new ArgumentException($"SamplingAttempts {samplingResolution} cannot be <= 0"); } var superSampledPoints = new NativeList <float2>(allocator); var sampleJob = new SampleJob { width = width + minimumRadius * 2, height = height + minimumRadius * 2, minimumRadius = minimumRadius, seed = seed, samplingResolution = samplingResolution, samples = superSampledPoints }.Schedule(); var croppedSamples = new NativeList <float2>(allocator); new CropJob { width = width, height = height, minimumRadius = minimumRadius, superSampledPoints = superSampledPoints.AsDeferredJobArray(), croppedSamples = croppedSamples }.Schedule(sampleJob).Complete(); superSampledPoints.Dispose(); return(croppedSamples); }
/// <summary> /// Schedules a multi-threaded job to generate an array of samples /// </summary> /// <param name="sampler">The sampler to generate samples from</param> /// <param name="sampleCount">The number of samples to generate</param> /// <param name="jobHandle">The handle of the scheduled job</param> /// <typeparam name="T">The type of sampler to sample</typeparam> /// <returns>A NativeArray of generated samples</returns> public static NativeArray <float> GenerateSamples <T>( T sampler, int sampleCount, out JobHandle jobHandle) where T : struct, ISampler { var samples = new NativeArray <float>( sampleCount, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); jobHandle = new SampleJob <T> { sampler = sampler, samples = samples }.ScheduleBatch(sampleCount, k_SamplingBatchSize); return(samples); }
public override async Task<bool> InvokeAsync(string paramList) { OutputInformation("Job Status: {0}", SingletonSampleJob.Instance.IsRunning); if (SingletonSampleJob.Instance.IsRunning) { OutputInformation("Running non-static job"); var job = new SampleJob(_context); job.RunAsync(null); await Task.Delay(1000); OutputInformation("Non-static Job Status: {0}", job.IsRunning); Jobs.Add(job); } return true; }
/// <summary> /// IJobの実行。 /// </summary> void ExecuteSampleJob() { // バッファ生成。 var result = new NativeArray <int>(processCount, Allocator.TempJob); // ジョブ生成。 var sampleJob = new SampleJob(); sampleJob.value1 = 10; sampleJob.value2 = 20; sampleJob.result = result; // ジョブ実行。 var jobHandle = sampleJob.Schedule(); // ジョブ完了待機。 jobHandle.Complete(); // バッファの破棄。 result.Dispose(); }
public void JobLoopPerf() { const int iterations = 10000; var metrics = new InMemoryMetricsClient(); var job = new SampleJob(metrics); job.RunContinuous(null, iterations); metrics.DisplayStats(_writer); }
public async Task JobLoopPerf() { const int iterations = 10000; var metrics = new InMemoryMetricsClient(); var job = new SampleJob(metrics, Log); var sw = Stopwatch.StartNew(); await job.RunContinuousAsync(null, iterations); sw.Stop(); await metrics.FlushAsync(); _logger.Trace((await metrics.GetCounterStatsAsync("runs")).ToString()); _logger.Trace((await metrics.GetCounterStatsAsync("errors")).ToString()); _logger.Trace((await metrics.GetCounterStatsAsync("failed")).ToString()); _logger.Trace((await metrics.GetCounterStatsAsync("completed")).ToString()); }
public ScheduledJobRegistry(DateTime appointment) { IJob job = new SampleJob(); JobManager.AddJob(job, s => s.ToRunOnceIn(5).Seconds()); }