Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SauronDark · Dec 19, 2018 at 03:17 PM · c#scripting problemthreadsmultithreading

IJobParallelForTransform is not Multi threaded?

when i Schedule " IJobParallelFor ", Profiler shows that all item are properly divided into batches and executed by all Workers threads equally, but not in the case of " IJobParalleteForTransform ", it just randomly pick just one single thread and let the main thread waiting longer in worst cases, if anyone know the fix, pls reply me and help me with this issue, Example code and Profiler Screenshot below,

So first here is the test script

Job script

 //this job to calculate just positions loop 
 public struct XLoop : IJobParallelFor
 {
     public NativeArray<Vector3> posJ;
     //some several other variables
 
     public void Execute(int i)
     {
         //some calculations on local var x, y and z
         posJ[i] = new Vector3(x, y, z);
     }
 }
 
 //this job helps to just transform GameObjects
 public struct GOPos : IJobParallelForTransform
 {
     [ReadOnly] public NativeArray<Vector3> pos;
 
     public void Execute(int index, TransformAccess transform)
     {
         transform.position = pos[index];
     }
 }

Main Script:

 public class Graph : MonoBehaviour
 {
 
     private JobHandle mathHandle;
     private XLoop mathLoop;
     private JobHandle gOHandle;
     private GOPos gOpos;
     private TransformAccessArray transforms;
     private NativeArray<Vector3> pos;
     //and some other var, not important to include here
 
     private void Awake()
     {
         //this TransformArray is created struct, and "points" object of Transform in array
         TransformArray.points = new Transform[10000];
 
         //instantiating all the gameOject into array
         for (int i = 0; i < TransformArray.points.Length; i++)
         {
             TransformArray.points[i] = Instantiate(pointPrefab, new Vector3(0f, 0f, -10f), Quaternion.identity, transform);
         }
         transforms = new TransformAccessArray(TransformArray.points, -1);
     }
     
     private void Update()
     {
         pos = new NativeArray<Vector3>(TransformArray.points.Length, Allocator.TempJob);
         mathLoop = new XLoop()
         {
             posJ = pos,
             //several other var for calculations in this job
         };
 
         gOpos = new GOPos()
         {
             pos = pos
         };
 
         mathHandle = mathLoop.Schedule(ResVar.CurrentFrameRes, 64);
         mathHandle.Complete();
         gOHandle = gOpos.Schedule(transforms , mathHandle);
 
         JobHandle.ScheduleBatchedJobs();
  }
 
  private void LateUpdate()
  {
        gOHandle.Complete();
        pos.Dispose();
   }
 
    //when this gameObjec Disables/Inactive
    private void OnDisable()
    {
         mathHandle.Complete();
         transforms.Dispose();
     }
 }

alt text

info related to attached Screenshot Image:

-"GOpos" (transform job) is depended on "Xloop" (pos calculation Job).

-"Xloop" is Implementing IJobParallelFor (mean all items are divided into batches) this worked good because it take Parameter as (int index, int batch count), so I can set how many Batches I want to Execute.

-However, GOPos is Implementing IJobParallelForTransform which take just one parameter as (transform array), meaning, it is taking Index from Transform.length, but not batch count, so i cannot set batch and so by default all item in the array are executed in one single Batch.

capture.png (37.8 kB)
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SauronDark · Dec 21, 2018 at 06:33 AM 0
Share

any one plz help

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by SauronDark · Dec 26, 2018 at 02:01 PM

so i finally found myself after a bit more digging, such a simple solution

https://forum.unity.com/threads/ijobparallelfortransform-15000-transforms-executed-on-single-job-thread-any-hints.537723/

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

168 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity Threading Issue: Not able to delegate task 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

IJobParralelFor giving me random result. 0 Answers

How to use multi-threading on Hololens 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges