Пример #1
0
  /** Test that MT is faster then ST. Assumes we always run on a MT box */
  public void _testMTFaster() {
    // TODO:  this test does not always works so removing for now
    int size1 = 800;
    int size2 = 800;
    byte state1 = Grid.INSIDE;
    byte state2 = Grid.INSIDE;

    Grid grid1 = new ArrayGridByte(size1, size1, size1, 0.001, 0.001);
    Grid grid2 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);
    Grid grid3 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);

    for (int y = 0; y < grid1.getHeight(); y++) {
      for (int x = 0; x < grid1.getWidth(); x++) {
        for (int z = 0; z < grid1.getDepth(); z++) {
          grid1.setState(x, y, z, state1);
        }
      }
    }
    for (int y = 0; y < grid2.getHeight(); y++) {
      for (int x = 0; x < grid2.getWidth(); x++) {
        for (int z = 0; z < grid2.getDepth(); z++) {
          grid2.setState(x, y, z, state1);
        }
      }
    }

    int WARMUP = 3;

    long st_time = 0;
    for (int i = 0; i < WARMUP; i++) {
      long t0 = System.currentTimeMillis();
      // get the subtraction of grid1 from grid2
      SubtractOpMT op = new SubtractOpMT(grid1, Runtime.getRuntime().availableProcessors());
      Grid subtrGridMT = op.execute(grid2);

      long mt_time = System.currentTimeMillis() - t0;
      t0 = System.currentTimeMillis();
      SubtractOp op2 = new SubtractOp(grid1, 0, 0, 0, 1);
      Grid subtrGridST = op2.execute(grid2);
      st_time = System.currentTimeMillis() - t0;

      // printf("MT time: %6d  ST time: %6d  SpeedUp: %6.2f\n",mt_time,st_time,(float)st_time /
      // mt_time);
    }

    int TIMES = 1;

    int cores = Runtime.getRuntime().availableProcessors();
    cores = Math.min(cores, 16); // We expect linear scaling to stop by this time
    float expected_speedup = 0.5f * cores;

    for (int i = 0; i < TIMES; i++) {
      long t0 = System.currentTimeMillis();
      // get the subtraction of grid1 from grid2
      SubtractOpMT op = new SubtractOpMT(grid1, Runtime.getRuntime().availableProcessors());
      op.setThreadCount(cores);
      op.setSliceSize(2);
      Grid subtrGridMT = op.execute(grid2);
      if (subtrGridMT.getWidth() > 10000) {
        System.out.println("no optimize away");
      }
      ;

      long mt_time = System.currentTimeMillis() - t0;

      float speedup = (float) st_time / mt_time;
      printf("MT time: %6d  ST time: %6d  SpeedUp: %6.2f\n", mt_time, st_time, speedup);

      assertTrue("Speedup factor > " + expected_speedup, speedup >= expected_speedup);
    }
  }
Пример #2
0
  /** Test basic operation */
  public void testBasic() {
    int size = 10;

    AttributeGrid grid = new ArrayAttributeGridByte(size, size, size, 0.001, 0.001);

    for (int y = 2; y < 8; y++) {
      for (int z = 2; z < 8; z++) {
        setX(grid, y, z, Grid.INSIDE, 1, 2, 7);
      }
    }

    int erosionDistance = 1;

    ErosionCube ec = new ErosionCube(erosionDistance);
    Grid erodedGrid = ec.execute(grid);

    int width = erodedGrid.getWidth();
    int height = erodedGrid.getHeight();
    int depth = erodedGrid.getDepth();
    for (int y = 0; y < height; y++) {
      for (int z = 0; z < depth; z++) {
        for (int x = 0; x < width; x++) {
          byte state = erodedGrid.getState(x, y, z);
          //                    System.out.println(x + ", " + y + ", " + z + ": " + state);

          if (y >= 2 && y < 6) {
            if (z >= 2 && z < 6) {
              if (x >= 2 && x < 6) {
                assertEquals(
                    "State of (" + x + " " + y + " " + z + " is not interior", Grid.INSIDE, state);
              } else {
                assertEquals(
                    "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
              }
            } else {
              assertEquals(
                  "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
            }
          } else {
            assertEquals(
                "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
          }
        }
      }
    }
    /*
            erosionDistance = 2;

            ec = new ErosionCube(erosionDistance);
            erodedGrid = ec.execute(grid);

            width = erodedGrid.getWidth();
            height = erodedGrid.getHeight();
            depth = erodedGrid.getDepth();
            for (int y=0; y<height; y++) {
                for (int z=0; z<depth; z++) {
                    for (int x=0; x<width; x++) {
                        System.out.println(x + ", " + y + ", " + z + ": " + erodedGrid.getState(x, y, z));
                    }
                }
            }
    */
  }