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"

How do I get the core count?

I was wondering if someone knew how t get the core count of a the running machine.

Product Version: UE 4.8
more ▼

asked Aug 03 '15 at 04:56 AM in C++ Programming

avatar image

822 38 39 241

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

3 answers: sort voted first

You should use our generic API wrappers to do this so the code works on all platforms:


Also don't use the FGenericPlatform* directly since that means you'll get the wrong version of that code when it's different for a given platform. These aren't virtual functions. We use typecasting to make it appear as if they are. We do this to avoid the virtual function overhead.

more ▼

answered Aug 04 '15 at 07:24 PM

avatar image

joeGraf STAFF
1.5k 35 12 69

avatar image MJ_01 Aug 06 '15 at 06:32 AM

I figured that out and posted it in my answer along with a post on what I believe is a bug.

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


on windows you can do it with WinApi https://msdn.microsoft.com/en-us/library/ms683194

more ▼

answered Aug 03 '15 at 05:05 AM

avatar image

576 54 46 72

avatar image MJ_01 Aug 03 '15 at 08:45 AM

Does epic not have a cross platform solution implemented?

avatar image happyhorror Aug 03 '15 at 10:00 AM

cross platform solution implementation not really about epic and UE4 itself, it's more between C++ developers, different OS and hardware developers

i don't know how else software can get access to hardware except drivers and in case drives OS dependant i don't sure C++ can offer natively same way for every OS+hardware combination, because it really too much depend on them

you may try dig into CPUID way descibed here http://stackoverflow.com/questions/2901694/programatically-detect-number-of-physical-processors-cores-or-if-hyper-threading , but people there arguing about how correct result is

little question, what for you want know number of cores?

you should know that "one thread designed code" won't work faster on multicore CPU because code logic can't be executed separatly and in case of code written on "events" in UE4 probably would be auto managed over all CPU because of C++ compilier and OS optimisation for multycore CPU itself

better result you probably may get only in case you're a hardcore geek and know too much about inner OS, drives and hardware implementations, guess it's not about you and me :)

avatar image MJ_01 Aug 04 '15 at 09:24 AM

Epic has a solution implemented but it doesn't seem to be working correctly.

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

After more hours that I would like to to admit of searching the source, I came across this: FGenericPlatformMisc::NumberOfCoresIncludingHyperthreads

It detects my cores but despite "IncludingHyperthreads", it's not detecting them.


I posted a bug report with a possible fix HERE.

In the meantime FPlatformMisc::NumberOfCoresIncludingHyperthreads() is a valid solution.

more ▼

answered Aug 04 '15 at 09:27 AM

avatar image

822 38 39 241

avatar image happyhorror Aug 04 '15 at 09:48 AM

i'm lack knowledges on core optimisation, but guess, it's WinAPI https://msdn.microsoft.com/en-us/library/ms683194 GetLogicalProcessorInformation

 int32 FWindowsPlatformMisc::NumberOfCores()
     static int32 CoreCount = 0;
     if (CoreCount == 0)
         if (FParse::Param(FCommandLine::Get(), TEXT("usehyperthreading")))
             CoreCount = NumberOfCoresIncludingHyperthreads();
             // Get only physical cores
             ::DWORD BufferSize = 0;
             // Get the size of the buffer to hold processor information.
             ::BOOL Result = GetLogicalProcessorInformation(InfoBuffer, &BufferSize);
             check(!Result && GetLastError() == ERROR_INSUFFICIENT_BUFFER);
             check(BufferSize > 0);
             // Allocate the buffer to hold the processor info.
             InfoBuffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)FMemory::Malloc(BufferSize);
             // Get the actual information.
             Result = GetLogicalProcessorInformation(InfoBuffer, &BufferSize);
             // Count physical cores
             const int32 InfoCount = (int32)(BufferSize / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION));
             for (int32 Index = 0; Index < InfoCount; ++Index)
                 SYSTEM_LOGICAL_PROCESSOR_INFORMATION* Info = &InfoBuffer[Index];
                 if (Info->Relationship ==  RelationProcessorCore)
     return CoreCount;
avatar image happyhorror Aug 04 '15 at 09:49 AM

i don't sure code sample from WinAPI will give you different result, the only way check it - experiment, so compile it and see if result same or not, if result same, then maybe you misunderstood something in difinitions of logical/physical cores and what actually matter or can be used, also you have to note that maybe there's no need to manually drive cores, because OS have own optimisation and split CPU load on cores, the only thing you need to do is allow multythreading so separate threads can be executed on other cores, the only way achieve it i know is FTickFunction and it's property bRunOnAnyThread https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/FTickFunction/ but have no example of use

avatar image MJ_01 Aug 04 '15 at 10:26 AM

I did do a test using the proper implimentation adn got the results I expected. I dug through the UE4 source some more and found the issue. I believe it to be a bug and posted a bug report.

avatar image happyhorror Aug 04 '15 at 10:49 AM

since you did investigation and sure it's bug, advice you report it on forum https://forums.unrealengine.com/forumdisplay.php?24-Feedback-for-Epic just to be sure Epic Staff see it

avatar image happyhorror Aug 04 '15 at 10:51 AM

and i really interested what for you want know number of cores on device? are you about to manage them manually, want calculate maximum load CPU capasity?

(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