Search Unity

Question about IJobForEach and Parallelism

Discussion in 'Data Oriented Technology Stack' started by PublicEnumE, Aug 22, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    106
    A dumb question about IJobForEach:

    (from the documentation @ https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/entity_iteration_job.html):
    Does this mean that:

    1. The IJobForEach is scheduled as a single job, which iterates over each of the qualifying entities in sequence on a single thread, and operates in parallel to other unrelated jobs?

    2. The IJobForEach creates a different job for each qualifying entity, and schedules each of these jobs to run in parallel with each other, in addition to other, unrelated jobs? <--(similar to an IJobParallelFor)

    I'm...pretty sure it's #1. But I'm not 100%. Would someone mind clarifying?

    Many thanks.
     
  2. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    461
    tldr:
    .Schedule(...)
    => parallel
    .ScheduleSingle(...)
    => one thread

    more specifically, ScheduleSingle runs the job in a single thread so you can write to full range of native containers/CDFE.
    Schedule processes each chunk in parallel, then inside the chunk the data is processed sequentially
     
    PublicEnumE likes this.
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    106
    Thank you!

    Also, I am dumb. It says it right here: https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/entity_iteration_job.html