Search Unity

Question Question About the Job System

Discussion in 'C# Job System' started by LetmeDwight, Dec 13, 2020.

  1. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    When I do something with the job system, Unity divides tasks across multiple cores. How can I be sure that I am not trying to distribute more jobs than there are at all? e.g. What if someone still has a 2 core CPU and I have jobs for at least 3 cores? Does the Uni ty Job system handle it by itself, or do I have to somehow query how much kernew is available in order to then be able to execute the corresponding ready-made scripts for which a script for 2 core CPUs and a script for CPUs with 4 cores or something? And how exactly does it work when I do this with an Android game for smartphones? is it exactly the same there because smartphones also have multiple cores or do I have to do it differently there?
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Imagine the job system like a queue of tasks. Unity initially creates worker threads for you. When one of them has nothing to do, it picks a task from the queue. Threads are run on any of the cpu cores. How many of those exist does not matter (in the context of this question at least).

    If someone only had one cpu core, it would simply run all the work sequentially. The only somewhat relevant decision in all of this is how many worker threads you create. However, Unity takes care of that decision for you. So there is really not a whole lot you can do wrong, as long as it runs and does what you want.

    I have never build anything using DOTS for phones, but i dont think there is any difference. Unity handles the cross platform stuff for you. You just write the code. As long as everything is working on Unitys end and the conversion to native phone code, this should be none of your concern.
     
    LetmeDwight likes this.
  3. LetmeDwight

    LetmeDwight

    Joined:
    Apr 9, 2020
    Posts:
    125
    And up to how many cores is it supported? I e.g. have 16 physical cores with 3.3GHz each. Will the whole thing then be split up to 16 cores or will it stop with 8 cores at some point?
     
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Why would it stop at some arbitrary number? In theory there should be no difference for whether you run it with 4 or 64 cores. That does not matter. In reality there will eventually be some limit. However, whether that's at 127 or 4 billion physical cores, for all practical intents and purposes such a limit does not exist. And should we ever reach the point where these core counts are considered normal, they will make it work.

    In conclusion, i dont know of a limit. But it's a system that's also marketed at server developers, so it will definitely work with however many cores your gaming / consumer grade customers may have.
     
    LetmeDwight likes this.