// Start is called before the first frame update void Start() { // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Set up the job data MyJob jobData = new MyJob(); jobData.a = 10; jobData.b = 10; jobData.result = result; // Schedule the job JobHandle handle = jobData.Schedule(); // Wait for the job to complete handle.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; // Free the memory allocated by the result array result.Dispose(); TextManager.Instance.Set($"Sum is {aPlusB}"); }
private static ITrigger CreateTrigger(MyJob myJob) { return(TriggerBuilder.Create() .WithIdentity($"{myJob.Type.FullName}.trigger") .WithCronSchedule(myJob.Expression) .WithDescription(myJob.Expression).Build()); }
private void Update() { if (Input.GetKeyDown(KeyCode.Y)) { float startTime = Time.realtimeSinceStartup; for (int i = 0; i < myNumbers.Length; i++) { myNumbers[i] = Sigmoid(myNumbers[i]); } Debug.Log("Without jobs: " + (Time.realtimeSinceStartup - startTime)); } if (Input.GetKeyDown(KeyCode.U)) { float startTime = Time.realtimeSinceStartup; NativeArray <float> numbersToCompute = new NativeArray <float>(myNumbers.Length, Allocator.TempJob); numbersToCompute.CopyFrom(myNumbers); MyJob myJob = new MyJob() { numbers = numbersToCompute }; JobHandle jobHandle = myJob.Schedule(numbersToCompute.Length, 64); jobHandle.Complete(); Debug.Log("With jobs: " + (Time.realtimeSinceStartup - startTime)); numbersToCompute.Dispose(); } }
void Update() { if (_segments == null) { return; } _segments.Dependency.Complete(); if (_segments.buffer.Length != _numSegments || _everyFrame) { _segments.buffer.Length = _numSegments; // scheduel new job: var job = new MyJob { Transform = transform.localToWorldMatrix, NumSegments = _numSegments, Segments = _segments.buffer, Offset = Time.time, Frequency = _frequency, }; _segments.Dependency = job.Schedule( arrayLength: _numSegments, innerloopBatchCount: 64, dependsOn: _segments.Dependency ); } }
/// Start /// <summary> /// Invoked on Start /// </summary> void Start() { // populate input and output native arrays var input = new NativeArray <float>(10, Allocator.Persistent); var output = new NativeArray <float>(1, Allocator.Persistent); for (int i = 0; i < input.Length; i++) { input[i] = 1.0f * i; } // create a job var job = new MyJob { Input = input, Output = output }; // schedule and complete job.Schedule().Complete(); Debug.Log("The result of the sum is: " + output[0]); // dispose all native parts input.Dispose(); output.Dispose(); }
void Update() { //按下鼠标左键后 if (Input.GetMouseButtonDown(0)) { //随机设置坐标 NativeArray <Vector3> position = new NativeArray <Vector3>(cubes.Length, Allocator.Persistent); for (int i = 0; i < position.Length; i++) { position[i] = Vector3.one * i; } //设置Transform TransformAccessArray transformArray = new TransformAccessArray(cubes); //启动工作线程 MyJob job = new MyJob() { position = position }; JobHandle jobHandle = job.Schedule(transformArray); //等待工作线程结束 jobHandle.Complete(); Debug.Log("工作线程结束"); //结束 transformArray.Dispose(); position.Dispose(); } }
public float Calculate() { // Schedule the job on each frame to make sure that it will be compiled async on the next frame _array[0] = 0.0f; // Launch synchronous job var job = new MyJob { Result = _array }; job.Schedule().Complete(); var rotation = job.Result[0]; // Launch an async compilation var asyncJobNoOptim = new MyJobWithDefaultOptimizations() { Result = _arrayAsyncJobDefault }; var asyncJobFastOptim = new MyJobWithFastOptimizations() { Result = _arrayAsyncJobFast }; var asyncJobNoOptimHandle = asyncJobNoOptim.Schedule(); var asyncJobFastOptimHandle = asyncJobFastOptim.Schedule(); // Wait for async completion asyncJobNoOptimHandle.Complete(); asyncJobFastOptimHandle.Complete(); return(rotation); }
public void jobTesting() { NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Setup the data for job #1 MyJob jobData = new MyJob(); jobData.a = 10; jobData.b = 10; jobData.result = result; // Schedule job #1 JobHandle firstHandle = jobData.Schedule(); // Setup the data for job #2 AddOneJob incJobData = new AddOneJob(); incJobData.result = result; // Schedule job #2 JobHandle secondHandle = incJobData.Schedule(firstHandle); // Wait for job #2 to complete secondHandle.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; Debug.Log(aPlusB); // Free the memory allocated by the result array result.Dispose(); }
public void TestBurstCompile() { //using (NativeArray<float> inputArray = new NativeArray<float>(10, Allocator.Persistent)) //{ // using (NativeArray<float> outputArray = new NativeArray<float>(1, Allocator.Persistent)) // { // for (int i =0;i < inputArray.Length;++i) // { // inputArray[i] = 1.0f * i; // } // } //} NativeArray <float> inputArray = new NativeArray <float>(10, Allocator.Persistent); NativeArray <float> outputArray = new NativeArray <float>(1, Allocator.Persistent); var job = new MyJob { Input = inputArray, Output = outputArray, }; for (int i = 0; i < inputArray.Length; ++i) { inputArray[i] = 1.0f * i; } job.Schedule().Complete(); Debug.Log("The result of the sum is: " + outputArray[0]); inputArray.Dispose(); outputArray.Dispose(); }
public async Task <IActionResult> PutMyJob(int id, MyJob myJob) { if (id != myJob.Id) { return(BadRequest()); } _context.Entry(myJob).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MyJobExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private void Start() { // Create a native array of a single float to store the result in. This example waits for the job to complete NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Setup the data for job #1 MyJob jobData = new MyJob(); jobData.a = 10; jobData.b = 10; jobData.result = result; // Schedule job #1 JobHandle firstHandle = jobData.Schedule(); // Setup the data for job #2 AddOneJob incJobData = new AddOneJob(); incJobData.result = result; // Schedule job #2 JobHandle secondHandle = incJobData.Schedule(firstHandle); // Wait for job #2 to complete secondHandle.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; // Free the memory allocated by the result array result.Dispose(); Debug.Log($"O valor de sei la o que é {aPlusB}"); }
void jobTest() { NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Set up the job data MyJob jobData = new MyJob { a = 10, b = 10, result = result }; // Schedule the job JobHandle handle = jobData.Schedule(); // Wait for the job to complete handle.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; Debug.Log(result[0]); // Free the memory allocated by the result array result.Dispose(); }
void ScheduleTestJob() { // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); MyJob tempJob = new MyJob(); tempJob.a = 10; tempJob.b = 10; tempJob.result = result; JobHandle tempJobHandle = tempJob.Schedule(); // Setup the data for job #2 AddOneJob addOneJob = new AddOneJob(); addOneJob.result = result; JobHandle secondJobHandle = addOneJob.Schedule(tempJobHandle); secondJobHandle.Complete(); float resultValue = result[0]; Debug.Log("Result of the myJob: " + resultValue); result.Dispose(); }
void StartMyJob() { // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Set up the job data MyJob jobData = new MyJob(); jobData.a = 10; jobData.b = 10; jobData.result = result; JobB jobB = new JobB(); jobB.result = result; // Schedule the job JobHandle handle = jobData.Schedule(); JobHandle hB = jobB.Schedule(handle); // Wait for the job to complete hB.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; Debug.Log(aPlusB); // Free the memory allocated by the result array result.Dispose(); }
protected override void OnStartRunning() { var comps = GetEntities <Components>(); if (comps.Length == 0) { return; } var speeds = new float[comps.Length]; var trs = new Transform[comps.Length]; for (int i = 0; i < trs.Length; i++) { speeds[i] = comps[i].mover.speed; trs[i] = comps[i].tr; } transAccessArray = new TransformAccessArray(trs); nativeSpeeds = new NativeArray <float>(speeds, Allocator.TempJob); job = new MyJob { speeds = nativeSpeeds }; }
private void Update_DoJob(float deltaTime) { // Check if I already have a job. if (MyJob == null) { GetNewJob(); // This should only be the case, if there was a pathing issue // or insufficent materials after getting the job. // In that case, just return early. if (MyJob == null) { return; } } // Make sure all materials are in place. if (CheckForJobMaterials()) { // If we get here, then the job has all the material that it needs. // Lets make sure that our destination tile is the job site tile. DestTile = JobTile; // Check if we have reached the destination tiles. if (CurrTile == DestTile) { // We are at the correct tile for our job, so // execute the job's "DoWork", which is mostly // going to countdown jobTime and potentially // call its "Job Complete" callback. MyJob.DoWork(deltaTime); } } }
//多个jobs依赖关系 public void SchedulingTwoJobs() { NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); MyJob jobData = new MyJob(); jobData.a = 10; jobData.b = 10; jobData.result = result; // 设置第一个任务开关 JobHandle firstHandle = jobData.Schedule(); //设置第二个任务 AddOneJob incJobData = new AddOneJob(); incJobData.result = result; // UnityEngine.Debug.Log(result[0]); //设置依赖 JobHandle secondHandle = incJobData.Schedule(firstHandle); //等待完成 secondHandle.Complete(); float aPlusB = result[0]; UnityEngine.Debug.Log(aPlusB); //释放资源 result.Dispose(); }
// Start is called before the first frame update void Start() { // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes NativeArray <float> result = new NativeArray <float>(1, Allocator.TempJob); // Set up the job data MyJob jobData = new MyJob(); //jobData.obj = new TestA(); jobData.a = 10; jobData.b = 10; jobData.result = result; // Schedule the job JobHandle handle = jobData.Schedule(); // Wait for the job to complete handle.Complete(); // All copies of the NativeArray point to the same memory, you can access the result in "your" copy of the NativeArray float aPlusB = result[0]; // Free the memory allocated by the result array result.Dispose(); var sw = new System.Diagnostics.Stopwatch(); var a = new NativeArray <long>(4096, Allocator.Temp); var b = new long[4096]; var count = 10000000; Random.InitState(0); long s = 0; var monitor = new object(); sw.Restart(); for (int i = 0; i < count; i++) { var index = Random.Range(0, 4096); b[index] = Random.Range(int.MinValue, int.MaxValue); s += b[index]; } sw.Stop(); Debug.Log($"{sw.ElapsedTicks}, {sw.ElapsedMilliseconds}, {s}"); // 0,0000509 Random.InitState(0); s = 0; sw.Restart(); for (int i = 0; i < count; i++) { lock (monitor) { var index = Random.Range(0, 4096); b[index] = Random.Range(int.MinValue, int.MaxValue); s += b[index]; } } sw.Stop(); Debug.Log($"{sw.ElapsedTicks}, {sw.ElapsedMilliseconds}, {s}"); }
public JsonResult AddJob1([FromServices] RecurringJobManager jobManager) { string id = Guid.NewGuid().ToString("N"); jobManager.AddOrUpdate(id, () => MyJob.即時任務(null), Cron.Minutely); return(Json(new { success = true, id })); }
protected void Button2_Click(object sender, EventArgs e) { MyJob j = new MyJob(); j.PostingID = int.Parse(Request.QueryString["id"]); j.UserName = Profile.UserName; MyJob.Insert(j); }
public async Task <IActionResult> PostmyJob(MyJob myjob) { await _context.MyJob.AddAsync(myjob); await _context.SaveChangesAsync(); return(StatusCode(201)); }
protected override JobHandle OnUpdate(JobHandle handle) { var job = new MyJob { TranslationType = GetArchetypeChunkComponentType <Translation>(true /* isReadOnly */), }; handle = job.Schedule(m_Query, handle); return(handle); }
public IEnumerator JobSystem() => UniTask.ToCoroutine(async() => { var job = new MyJob() { loopCount = 999, inOut = new NativeArray <int>(1, Allocator.TempJob) }; JobHandle.ScheduleBatchedJobs(); await job.Schedule(); job.inOut[0].Should().Be(999); job.inOut.Dispose(); });
protected override JobHandle OnUpdate(JobHandle inputDeps) { var job = new MyJob() { Commands = this.commands.CreateCommandBuffer().ToConcurrent() }; var handle = job.Schedule(this.query, inputDeps); this.commands.AddJobHandleForProducer(handle); return(handle); }
public async UniTask JobSystem() { var job = new MyJob() { loopCount = 999, inOut = new NativeArray <int>(1, Allocator.TempJob) }; await job.Schedule(); job.inOut[0].Is(999); job.inOut.Dispose(); }
public static void AddJob() { IMyJob myJob = new MyJob(); //This Constructor needs to be parameterless JobDetailImpl jobDetail = new JobDetailImpl("Job1", "Group1", myJob.GetType()); CronTriggerImpl trigger = new CronTriggerImpl("Trigger1", "Group1", "0 0/1 * 1/1 * ? *"); //run every minute between the hours of 8am and 5pm _scheduler.ScheduleJob(jobDetail, trigger); DateTimeOffset?nextFireTime = trigger.GetNextFireTimeUtc(); Console.WriteLine("Next Fire Time:" + nextFireTime.Value); }
// Start is called before the first frame update void Start() { nativeSpeeds = new NativeArray <float>(speeds, Allocator.TempJob); transAccessArr = new TransformAccessArray(trs); job = new MyJob { deltaTime = Time.deltaTime, speeds = nativeSpeeds }; }
static void Main(string[] args) { Console.WriteLine("Hello Quartz! Main"); StdSchedulerFactory factory = new StdSchedulerFactory(); IScheduler scheduler = factory.GetScheduler().Result; //将job和trigger注册到scheduler中 scheduler.ScheduleJob(MyJob.GetJobDetail(), MyJob.GetTrigger()); //start让调度线程启动[调度线程可以从job store中获取快要执行的trigger,然后获取trigger关联的job,执行job] scheduler.Start(); Console.ReadKey(); }
public void JobFunctionPointerTest() { var funcPtr = BurstCompiler.CompileFunctionPointer <DoThingDelegate>(DoThing); var job = new MyJob(); int value = 5; job.Blah = &value; job.FunctionPointer = funcPtr; job.Schedule().Complete(); Assert.AreEqual(6, value); }
void Update() { _batch.Dependency.Complete(); var buffer = _batch.buffer; buffer.Length = 3; var job = new MyJob { Buffer = buffer.AsArray(), LocalToWorld = transform.localToWorldMatrix }; _batch.Dependency = job.Schedule(_batch.Dependency); }
public static void Main(string[] args) { MyJob j1 = new MyJob(); j1.repetitions = 3; Thread thread1 = new Thread(new ThreadStart(j1.run_me)); thread1.Name = "first"; thread1.Start(); MyJob j2 = new MyJob(); j2.repetitions = 5; Thread thread2 = new Thread(new ThreadStart(j2.run_me)); thread2.Name = "second"; thread2.Start(); }