Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CPU Utilization Question  (Read 835 times)

GavinDruid

  • Escaped Lunatic
    • View Profile
CPU Utilization Question
« on: January 24, 2018, 05:14:18 pm »

Hello all,

I run Dwarf Fortress (the amd64 version) on Ubuntu Linux 16.04, and I can't help but notice that it appears to only be using one CPU core at any given moment. I am wondering if there is a way to enable multicore processing in DF, or is it a hardcoded setting that cannot be changed? I can give further system specs upon request if needed.

Thanks for your time.
Logged

Encrtia

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #1 on: January 24, 2018, 05:25:12 pm »

From everywhere I've ever read, it only utilizes one core.

Multi-threading isn't a thing, & you will be slapped for asking for it :P
Logged
~When death smiles at you, just smile one back.

PatrikLundell

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #2 on: January 24, 2018, 05:29:56 pm »

As mentioned, DF is essentially single threaded, so there's nothing you can do.
Logged

Shonai_Dweller

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #3 on: January 24, 2018, 05:34:49 pm »

From everywhere I've ever read, it only utilizes one core.

Multi-threading isn't a thing, & you will be slapped for asking for it :P
Ask for it and explain why it will help DF and you won't be slapped (except by those who think major rewrites of the game are out of the question - luckily not Toady apparently).

Problem is most multithreading threads end up with tech people pointing out that it won't help at all with the issues that cause performance problems (like pathfinding) and no-one with enough tech knowledge to counter them.
Logged

GavinDruid

  • Escaped Lunatic
    • View Profile
Re: CPU Utilization Question
« Reply #4 on: January 24, 2018, 05:37:09 pm »

Ah I understand...I realize DF uses an old code base, so I'm not surprised multi-threading support would be a major hassle. I just didn't know if it was already supported or not. Thanks for the help anyway!
Logged

They Got Leader

  • Bay Watcher
  • Current Fortress:
    • View Profile
    • Steam Profile
Re: CPU Utilization Question
« Reply #5 on: January 24, 2018, 09:25:17 pm »

Ah I understand...I realize DF uses an old code base, so I'm not surprised multi-threading support would be a major hassle. I just didn't know if it was already supported or not. Thanks for the help anyway!
One of the most major recent (43.05) updates was moving from 32-bit to 64-bit architecture. That change brought quite a bit of game improvement. I believe Toady discussed multi-threading (I can't find the source), but it would require an almost complete overhaul of the game to make it run smoothly.

Hello all,

I run Dwarf Fortress (the amd64 version) on Ubuntu Linux 16.04, and I can't help but notice that it appears to only be using one CPU core at any given moment. I am wondering if there is a way to enable multicore processing in DF, or is it a hardcoded setting that cannot be changed? I can give further system specs upon request if needed.

Thanks for your time.
However, I totally recommend this page on the Wiki for tips to improve FPS.
Logged
Quote from: Urist McDwarfFortress
You do not understand the ways of Toady One. He is not a business, he's just a guy trying to make a fun game. He's invited people to come along and experience the journey with him (and help him test it out as he goes along). At the end of the day, I don't think his main goal is to sell Dwarf Fortress, its just to create the best game possible.

Encrtia

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #6 on: January 24, 2018, 09:29:56 pm »

Nice link, good idea.

If it's not too much trouble, could you find that link? Would be curious to have a read.
Logged
~When death smiles at you, just smile one back.

They Got Leader

  • Bay Watcher
  • Current Fortress:
    • View Profile
    • Steam Profile
Re: CPU Utilization Question
« Reply #7 on: January 24, 2018, 09:44:01 pm »

Nice link, good idea.

If it's not too much trouble, could you find that link? Would be curious to have a read.
The multi-threading one? I can't find Toady talking about it specifically, but if you Google it, you can reveal how many computer science nerds peruse the forums and explain why it is a terrifying process. I can find you some if you want.
Logged
Quote from: Urist McDwarfFortress
You do not understand the ways of Toady One. He is not a business, he's just a guy trying to make a fun game. He's invited people to come along and experience the journey with him (and help him test it out as he goes along). At the end of the day, I don't think his main goal is to sell Dwarf Fortress, its just to create the best game possible.

Shonai_Dweller

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #8 on: January 24, 2018, 10:01:46 pm »

Nice link, good idea.

If it's not too much trouble, could you find that link? Would be curious to have a read.
The multi-threading one? I can't find Toady talking about it specifically, but if you Google it, you can reveal how many computer science nerds peruse the forums and explain why it is a terrifying process. I can find you some if you want.
Possibly 10th anniversary video? I think it's there he mentions having done some experimentation (so, we're not doing nothing!).
Logged

Sutremaine

  • Bay Watcher
  • [ETHIC:ATROCITY: PERSONAL_MATTER]
    • View Profile
Re: CPU Utilization Question
« Reply #9 on: January 25, 2018, 08:49:01 pm »

DF development has been consistent since 2006, but the project was started in 2002. Does having code that predates multicore processing make a single-threaded program any more difficult to convert to multi-thread, or is that a nonsensical question to somebody who knows anything about programming?
Logged
I am trying to make chickens lay bees as eggs. So far it only produces a single "Tame Small Creature" when a hen lays bees.
Honestly at the time, I didn't see what could go wrong with crowding 80 military Dwarves into a small room with a necromancer for the purpose of making bacon.

They Got Leader

  • Bay Watcher
  • Current Fortress:
    • View Profile
    • Steam Profile
Re: CPU Utilization Question
« Reply #10 on: January 25, 2018, 10:02:28 pm »

DF development has been consistent since 2006, but the project was started in 2002. Does having code that predates multicore processing make a single-threaded program any more difficult to convert to multi-thread, or is that a nonsensical question to somebody who knows anything about programming?
As far as I can tell, it has to do with the way the program is set up to handle calculations: These threads talk about it more.

This one talks briefly about multi-threading (information I did not know).

"You can buy a $1000 computer today with 4 CPU cores and 80 GPU cores.  But you can't design a compiler that automatically gets full benefit out of that -- not just because it's impractical, but because it's mathematically impossible.  For example, A* is pretty much explicitly serial: its entire benefit is from exploring what is usually the right path and not seeing anything else.  Lisp and matlab do a great job of warping the programmer's brain to think about doing the same operation on lots of data, which can then be relatively easily parallelized.  The more classically-trained programmers I work with find this all pretty mind-blowing, so it's going to take a generation or two before we can really get data-parallel languages in mass usage."


This one furthers the cause, and then talks about the processes involved with making and utilizing multi-thread. It gets interesting, but the people seem to come to the same conclusion: it would require a lot of rewriting.

This one is a bunch of pages of info, but summed up into one sentence: "Using multiple cores at all: Impossible without a total rewrite of the hooks that allow it to use even the one core." And is later broken down here.

I didn't look too deeply into it, but this reddit post Devlog by Toady may talk about it more.

You also can't write a program to multi-thread it.

In the end: it looks like it may be possible, but the underlying issue is that a lot of the commands are serial (must be done in sequence) and can not be shucked off to another thread. It is possible, but may not be feasible. As was written in the last link:
"It's not that simple.  For example, the code in Dwarf Fortress is designed to work serially, so it will likely behave quite badly when run in parallel.  Race conditions, such as one thread attempting to read/write/edit/delete data while another thread is attempting to read/write/edit/delete that same data, can produce erratic behavior or even crash the program.  For example, two dwarves deciding to do the same task at the same time could cause it to try to remove the same task from the list twice, which would likely screw up the task list, if not cause the program to crash entirely.  The current code wouldn't check for that because it would never happen when run serially."
Logged
Quote from: Urist McDwarfFortress
You do not understand the ways of Toady One. He is not a business, he's just a guy trying to make a fun game. He's invited people to come along and experience the journey with him (and help him test it out as he goes along). At the end of the day, I don't think his main goal is to sell Dwarf Fortress, its just to create the best game possible.

lethosor

  • Bay Watcher
    • View Profile
Re: CPU Utilization Question
« Reply #11 on: January 26, 2018, 09:37:53 pm »

DF development has been consistent since 2006, but the project was started in 2002. Does having code that predates multicore processing make a single-threaded program any more difficult to convert to multi-thread, or is that a nonsensical question to somebody who knows anything about programming?
The links above are good, but it has nothing to do with when Toady started writing DF. Threading libraries existed well before DF did - using multiple threads is distinct from using multiple cores. For example, a program with a GUI that also runs lots of calculations could have two threads, one for the GUI and one for the calculations. Assuming a reasonable thread implementation, the two tasks could still be interleaved, even if your computer only had a single core, so running long calculations wouldn't lock up the GUI.

To the original post: if there's anything several times more complicated than multithreading DF, it would be supporting both single and multiple threads and having an option to control it. (And technically, DF does use multiple threads already, for graphics/rendering/sound/input/etc., so if you're running a fort and maxing out your CPU resources on one core, you should notice CPU usage a bit over one core.)
Logged
DFHack - Dwarf Manipulator (Lua) - DF Wiki talk

There was a typo in the siegers' campfire code. When the fires went out, so did the game.