Found (a little bit) speed

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Found (a little bit) speed

by burli » Sun Jun 19, 2016 15:28

I'm tinker around with the source code and found a little bit speed.

I found a little bit speed in Mapgen::spreadLight() in mapgen.cpp. I was able to reduce the average value for the same mapchunks from 67ms to 37ms on my system

Another place is CavesRandomWalk::makeCave() in cavegen.cpp. I reduced the average time from 2783us to 1102us for this loop

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  for (u16 j = 0; j < tunnel_routepoints; j++)
    makeTunnel(j % dswitchint == 0);


I used in both cases the same position and the same yaw, so the same mapchunks/caves are generated

I don't want to make a party for this because this currently works with GCC on Linux and I'm not shure if something is messing up, but I think I will try to find more. But it is not easy

If you want to know what I'm doing: I tinker around with OpenMP
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Found (a little bit) speed

by rubenwardy » Sun Jun 19, 2016 17:21

Please share. If you can, create a pull request here: https://github.com/minetest/minetest
If not, please post the relevant changes here using

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
[code]paste your code like this[/code]
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Sun Jun 19, 2016 19:15

I don't want to make a pull request for that. It is to soon. The changes are simple. I add -fopenmp to src/CMakeList.txt

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG ${RELEASE_WARNING_FLAGS} ${WARNING_FLAGS} ${OTHER_FLAGS} -fopenmp -ffast-math -Wall -pipe -funroll-loops")


In cavegen.cpp I changed this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  // Generate some tunnel starting from orp
  #pragma omp parallel for
  for (u16 j = 0; j < tunnel_routepoints; j++)
    makeTunnel(j % dswitchint == 0);


and in mapgen.cpp this

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
void Mapgen::spreadLight(v3s16 nmin, v3s16 nmax)
{
//  TimeTaker t("spreadLight");
  VoxelArea a(nmin, nmax);
  #pragma omp parallel for default(shared)
  for (int z = a.MinEdge.Z; z <= a.MaxEdge.Z; z++) {


So I just add these #pragma lines. I tried other loops, but until now without success. The code has to be changed to make it work. OpenMP is limited, not any for loop can be parallelized just that easy. But the concept is interesting. It is relatively easy to parallelize specific parts of the code
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Sun Jun 19, 2016 19:53

Found a few ms in dungeongen.cpp

without optimization
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
dungeon: 6733us
dungeon: 6865us
dungeon: 8467us


with optimization
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
dungeon: 5119us
dungeon: 4684us
dungeon: 5037us


Not much, but I think there is potential for more. But I noticed, that mouse capture doesn't work sometimes, if I run Minetest from the terminal. I hope this is not caused by OpenMP

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  TimeTaker t("dungeon", NULL, PRECISION_MICRO);

  // Set all air and water to be untouchable
  // to make dungeons open to caves and open air
  #pragma omp parallel for default(shared)
  for (s16 z = nmin.Z; z <= nmax.Z; z++) {
    for (s16 y = nmin.Y; y <= nmax.Y; y++) {
      u32 i = vm->m_area.index(nmin.X, y, z);
      for (s16 x = nmin.X; x <= nmax.X; x++) {
        content_t c = vm->m_data[i].getContent();
        if (c == CONTENT_AIR || c == dp.c_water || c == dp.c_river_water)
          vm->m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE;
        i++;
      }
    }
  }

  // Add them
  for (u32 i = 0; i < floor(nval_density); i++)
    makeDungeon(v3s16(1, 1, 1) * MAP_BLOCKSIZE);

  // Optionally convert some structure to alternative structure
  if (dp.c_alt_wall == CONTENT_IGNORE)
    return;

  #pragma omp parallel for default(shared)
  for (s16 z = nmin.Z; z <= nmax.Z; z++)
  for (s16 y = nmin.Y; y <= nmax.Y; y++) {
    u32 i = vm->m_area.index(nmin.X, y, z);
    for (s16 x = nmin.X; x <= nmax.X; x++) {
      if (vm->m_data[i].getContent() == dp.c_wall) {
        if (NoisePerlin3D(&dp.np_alt_wall, x, y, z, blockseed) > 0.0f)
          vm->m_data[i].setContent(dp.c_alt_wall);
      }
      i++;
    }
  }
  printf("dungeon: %dus\n", t.stop());
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Mon Jun 20, 2016 09:16

I was able to speed up more. I reduced the spreadLight() function to an average of 28ms

The dungeon I could reduce from an average of 6512us without optimization (different dungeon than before) over 6018us with my first try of optimization to 3813us

All I had to do is to add schedule(dynamic) and I removed default(shared) because it is the default behaviour

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
  #pragma omp parallel for schedule(dynamic)
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Mon Jun 20, 2016 14:13

Ok, made a pull request. Hope that it worked. Was my first pull request

Edit: I'm affraid my editor messed up the indent. Normaly I work with an indent of 2 space, not with tabs
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Tue Jun 21, 2016 20:08

I tried my spreadLight patch on my AMD FX-6300 (Hexacore)

without
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
spreadLight: 34ms
spreadLight: 56ms
spreadLight: 49ms
spreadLight: 55ms
spreadLight: 65ms
spreadLight: 71ms
spreadLight: 5ms
spreadLight: 6ms
spreadLight: 72ms
spreadLight: 81ms
spreadLight: 61ms
spreadLight: 72ms
spreadLight: 76ms
spreadLight: 61ms
spreadLight: 74ms
spreadLight: 72ms


with
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
spreadLight: 19ms
spreadLight: 20ms
spreadLight: 16ms
spreadLight: 17ms
spreadLight: 20ms
spreadLight: 26ms
spreadLight: 2ms
spreadLight: 3ms
spreadLight: 30ms
spreadLight: 27ms
spreadLight: 23ms
spreadLight: 24ms
spreadLight: 25ms
spreadLight: 21ms
spreadLight: 23ms
spreadLight: 22ms


Significant improvement for one line of code I think
 

asanetargoss
Member
 
Posts: 36
Joined: Sun Apr 26, 2015 03:10

Re: Found (a little bit) speed

by asanetargoss » Sat Jun 25, 2016 17:03

What a small world. I just saw your post yesterday while randomly visiting the OpenMP forum. :0

You ask so many questions on the Minetest forum, burli. I knew you were up to no good. >:D

(Disclaimer: I've never actually used OpenMP before.)
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

Re: Found (a little bit) speed

by philipbenr » Sat Jun 25, 2016 23:36

That is a really latency reduction there. Was the PR merged?
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Sun Jun 26, 2016 05:11

No
 

User avatar
philipbenr
Member
 
Posts: 1665
Joined: Fri Jun 14, 2013 01:56
GitHub: philipbenr
IRC: philipbenr
In-game: WisdomFire or philipbenr

Re: Found (a little bit) speed

by philipbenr » Tue Jun 28, 2016 04:44

Darn. Well, every little bit helps, especially on older hardware. I hope that is merged soon. ;)
 

User avatar
burli
Member
 
Posts: 1313
Joined: Fri Apr 10, 2015 13:18

Re: Found (a little bit) speed

by burli » Tue Jun 28, 2016 05:55

philipbenr wrote:I hope that is merged soon. ;)

I don't think so. hmmmm is not keen, so I stopped this project
 


Return to Minetest Engine

Who is online

Users browsing this forum: No registered users and 9 guests

cron