Exemple #1
0
  /**
   * Transforms the specified array of times and marks. Known samples are those for which times are
   * zero, and times and marks for these known samples are used to compute times and marks for
   * unknown samples.
   *
   * @param times input/output array of times.
   * @param marks input/output array of marks.
   */
  public void apply(float[][][] times, int[][][] marks) {

    // Measure elapsed time in seconds.
    Stopwatch sw = new Stopwatch();
    sw.start();
    log.fine("TimeMarker3.apply: begin time=" + (int) sw.time());

    // Initialize all unknown times to infinity.
    for (int i3 = 0; i3 < _n3; ++i3) {
      for (int i2 = 0; i2 < _n2; ++i2) {
        for (int i1 = 0; i1 < _n1; ++i1) {
          if (times[i3][i2][i1] != 0.0f) times[i3][i2][i1] = INFINITY;
        }
      }
    }

    // Indices of known samples in random order.
    short[][] kk = indexKnownSamples(times);
    short[] k1 = kk[0];
    short[] k2 = kk[1];
    short[] k3 = kk[2];
    shuffle(k1, k2, k3);
    int nk = k1.length;

    // Array for the eikonal solution times.
    float[][][] t = new float[_n3][_n2][_n1];

    // Active list of samples used to compute times.
    ActiveList al = new ActiveList();

    // For all known samples, ...
    for (int ik = 0; ik < nk; ++ik) {
      if (ik % (1 + (nk - 1) / 100) == 0)
        log.fine("  apply: ik/nk=" + ik + "/" + nk + " time=" + (int) sw.time());
      int i1 = k1[ik];
      int i2 = k2[ik];
      int i3 = k3[ik];

      // Clear activated flags so we can tell which samples become activated.
      clearActivated();

      // Put the known sample with time zero into the active list.
      t[i3][i2][i1] = 0.0f;
      al.append(_s[i3][i2][i1]);

      // The mark for the known sample.
      int m = marks[i3][i2][i1];

      // Process the active list until empty.
      solve(al, t, m, times, marks);
    }

    // Log elapsed time.
    sw.stop();
    log.fine("TimeMarker3.apply: end time=" + (int) sw.time());
  }
Exemple #2
0
 private static void benchStream(File file, boolean buffered) throws IOException {
   System.out.println("buffered=" + buffered);
   Stopwatch sw = new Stopwatch();
   int nh = 60; // like a trace header
   int na = 1000; // like trace samples
   int[] h = randint(nh);
   float[] a = randfloat(na);
   double maxtime = 60.0, s;
   double mbytes = 4.0e-6 * (nh + na);
   long nw, nr, rate;
   FileOutputStream fos = new FileOutputStream(file);
   ArrayOutputStream aos =
       buffered
           ? new ArrayOutputStream(new BufferedOutputStream(fos))
           : new ArrayOutputStream(fos);
   sw.restart();
   for (nw = 0, s = 0.0; sw.time() < maxtime; ++nw) {
     s += sum(a);
     aos.writeInts(h);
     aos.writeFloats(a);
   }
   aos.close();
   sw.stop();
   rate = (int) (mbytes * nw / sw.time());
   System.out.println("ArrayOutputStream: sum=" + s + " nw=" + nw + " rate=" + rate);
   FileInputStream fis = new FileInputStream(file);
   ArrayInputStream ais =
       buffered ? new ArrayInputStream(new BufferedInputStream(fis)) : new ArrayInputStream(fis);
   sw.restart();
   for (nr = 0, s = 0.0; nr < nw; ++nr) {
     ais.readInts(h);
     ais.readFloats(a);
     s += sum(a);
   }
   ais.close();
   sw.stop();
   rate = (int) (mbytes * nr / sw.time());
   System.out.println(" ArrayInputStream: sum=" + s + " nr=" + nr + " rate=" + rate);
 }
Exemple #3
0
 private static void benchDouble(ArrayFile af, int n) throws IOException {
   double[] a = randdouble(n);
   double[] b = zerodouble(n);
   int nio;
   Stopwatch sw = new Stopwatch();
   sw.start();
   for (nio = 0; sw.time() < 5.0; ++nio) {
     af.seek(0);
     af.writeDoubles(a);
     af.seek(0);
     af.readDoubles(b);
   }
   sw.stop();
   for (int i = 0; i < n; ++i) if (a[i] != b[i]) throw new RuntimeException("double: i/o failure");
   double time = sw.time();
   double rate = 2.0 * 8.0e-6 * nio * n / time;
   System.out.println("double: rate=" + rate + " MB/s");
 }