x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why does the performance of my threaded code not increase when I use more than one thread?

I want to spawn a handful of threads at the start of a level that generate various pieces of a voxel terrain. The threads seem to function correctly, but for some reason it takes the same amount of time for the terrain to finish generating whether I split it across two threads or eight!

All I'm doing is creating a child of the FRunnable class, "FTerrainGenWorker", and starting its thread with

 Thread = FRunnableThread::Create(this, TEXT("FTerrainGenWorker"), 0,
                                   TPri_AboveNormal,
                                   FGenericPlatformAffinity::GetPoolThreadMask());


The Run() function for each thread just loops through a part of the voxel terrain grid and fills it in with noise:

 const FVector scale(0.1f, 0.1f, 0.1f);
 
 FVector pos;
 for (int32 z = MinZ; z <= MaxZ && z < Grid.NumZ(); ++z)
 {
     pos.Z = (float)z * scale.Z;
 
     for (int32 y = 0; y < Grid.NumY(); ++y)
     {
         pos.Y = (float)y * scale.Y;
 
         for (int32 x = 0; x < Grid.NumX(); ++x)
         {
             pos.X = (float)x * scale.X;
 
             Grid.Get(x, y, z) = NoiseGen::GetNoise(pos);
         }
     }

     FPlatformProcess::Sleep(0.005);
 }
 
     return 0;

The more threads I have, the smaller the range of Z values each thread works through, yet it always takes about 27-30 seconds whether I have 1, 4, or 8 threads! I don't see any problems with how I'm splitting my work, so is there something wrong with how I'm using FRunnable or thread affinities?

Product Version: UE 4.10
Tags:
more ▼

asked Feb 05 '16 at 10:04 PM in C++ Programming

avatar image

heyx3
1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Try to swap y and x loop declarations, check your data for cache alignments and cache miss. Depending on how your data is structured in memory you might invalidate cache lines by writing. try to use temporary arrays to store data and join when you are done with it..

more ▼

answered Mar 27 '17 at 03:11 AM

avatar image

Vertex Soup
288 4 22 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question