org.javaseis.io
Class SortCreate

java.lang.Object
  extended by org.javaseis.io.SortRead
      extended by org.javaseis.io.SortCreate

public class SortCreate
extends SortRead

Create a named "sort order" for an existing JavaSeis dataset. A "sort order" is a map that contains a list of traces for a different Volume/Frame ordering of the data. The sort order is defined by two trace properties, one for the third axis, one for the fourth axis. At the present time, only a 2-level sort is supported, but the design does not preclude more sort levels.

The sort order is defined by 3 files: SortProperties.name - Java Properties file describing the sort order SortVolumeMap.name - binary list of (LogicalVolume,FramesinVolume) pairs SortFrameMap.name - binary list of (LogicalFrame,TracesInFrame) pairs SortTraceMap.name - binary list of 64 bit trace numbers for the sort

The SortVolumeMap has "NumberOfVolumes" entries in increasing LogicalVolume order. Each entry consists of (LogicalVolume,FramesinVolume) 32 bit integers.

The SortFrameMap has "FramesPerVolume" * "NumberOfVolumes" locations, but for a sparse sort order some locations may not be filled. The "FrameMap" for a given volume starts at byte location 8*FramesPerVolume*volumeIndex in the SortFrameMap file, and has FramesInVolume entries stored as (LogicalFrame,TracesInFrame) 32 bit integers in increasing LogicalFrame order.

The SortTraceMap has TracePerFrame * FramesPerVolume * NumberOfVolumes entries, and may also be sparse. The "TraceMap" for a given volumeIndex and frameIndex starts at byte location 8*TracesPerFrame*FramesPerVolume*volumeIndex + 8*TracesPerFrame*frameIndex. The entries consist of TracesInFrame 64 bit integers that are the trace index locations in the JavaSeis dataset for the (LogicalVolume, LogicalFrame) sorted data.

Parallel Implementation:

 - Split the number of frames in the dataset across processors
 - read headers in parallel and select off axis 3 and 4 sort values
 - Locally sort into increasing order on each task
 - Exchange global counts from the local sorts
 - Divide the axis 4 sort across processors
 - Transpose to block and collect axis 4 lists
 - Re-sort locally on each task
 - Write sort maps out in parallel
 
Potential issues:
 - Currently only supports 2-level sort on 3rd and 4th axes
 - A very sparse dataset could lead to load imbalance on the parallel read
 - A sort order (though rare) could place all sorted traces on a single task
 

Author:
Chuck Mosher for JavaSeis.org

Nested Class Summary
 class SortCreate.SortCompare
           
 
Field Summary
(package private)  Decomposition dc
           
(package private)  SortMap[] ilist
           
protected  java.lang.String key3
           
protected  java.lang.String key4
           
(package private)  int localTraces
           
(package private)  int localVolumes
           
(package private)  SortMap[] olist
           
(package private)  Pacifier pacify
           
(package private)  IParallelContext pc
           
(package private)  int volumesPerTask
           
 
Fields inherited from class org.javaseis.io.SortRead
currentFrame, currentVolume, frameBuffer, frameMap, frameMapio, framesInVolume, framesPerVolume, frameView, label3, label4, logicalFrame, logicalVolume, maxLogFrm, maxLogVol, minLogFrm, minLogVol, sio, sort3, sort4, sortName, sprops, traceBuffer, traceMap, traceMapio, tracesInFrame, tracesInSort, tracesPerFrame, traceView, volumeBuffer, volumeMap, volumeMapio, volumes, volumeView
 
Constructor Summary
SortCreate(Seisio sioFile, java.lang.String name, java.lang.String sort3i, java.lang.String sort4i, Pacifier paci, IParallelContext pci)
          Create a new sort order for an open JavaSeis dataset
 
Method Summary
 void close()
           
(package private)  void frameIndexToPosition(long iframe, int nfpv, int[] position)
          Convert global frame index in a JavaSeis dataset to a volume/frame index location
(package private)  void globalCount()
          Collect global counts for traces/frames/volumes in sort order
static void main(java.lang.String[] args)
           
(package private)  void sortAllocateMaps()
          Allocate memory and buffers for sort order maps
(package private)  void sortCreateMaps(int ntrc_est)
          Create map files for a sort order
(package private)  void sortLocal(SortMap[] list)
          Loop through sort list and count traces, frames, and volumes
(package private)  void sortParallel()
          Parallel sort across tasks in a ParallelContext
(package private)  void sortWrite()
          Loop through sort list and write volume, frame, and trace maps
(package private)  long totalFrames(Seisio sio)
          Calculate the total number of potential frames in an open JavaSeis dataset.
(package private)  void writeFrameMap(int nfrm, int ivol)
          Write frame map for the current volume
(package private)  void writeTraceMap(int ntrc, int ivol, int ifrm)
          Write trace map for the current frame
(package private)  void writeVolumeMap(int nvol, int ivol)
          Write volume map for a subrange of volumes
 
Methods inherited from class org.javaseis.io.SortRead
delete, delete, exists, exists, getFrameLabel, getFrameLogicalDelta, getFrameLogicalOrigin, getNumFramesPerVolume, getNumTracesPerFrame, getNumVolumes, getVolumeLabel, getVolumeLogicalDelta, getVolumeLogicalOrigin, list, list, open, readFrame, setFrame, setPosition, setVolume
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dc

Decomposition dc

ilist

SortMap[] ilist

key3

protected java.lang.String key3

key4

protected java.lang.String key4

localTraces

int localTraces

localVolumes

int localVolumes

olist

SortMap[] olist

pacify

Pacifier pacify

pc

IParallelContext pc

volumesPerTask

int volumesPerTask
Constructor Detail

SortCreate

public SortCreate(Seisio sioFile,
                  java.lang.String name,
                  java.lang.String sort3i,
                  java.lang.String sort4i,
                  Pacifier paci,
                  IParallelContext pci)
           throws SeisException
Create a new sort order for an open JavaSeis dataset

Parameters:
sioFile - Seisio object for an open JavaSeis dataset
name - name of the sort order to be created
sort3 - trace property that will be used for axis 3 of the sort
sort4 - trace property for axis 4 of the sort
Throws:
SeisException
Method Detail

close

public void close()
Overrides:
close in class SortRead

frameIndexToPosition

void frameIndexToPosition(long iframe,
                          int nfpv,
                          int[] position)
Convert global frame index in a JavaSeis dataset to a volume/frame index location

Parameters:
iframe - input global frame in the dataset
nfpv - number of frames per volume in the dataset
position - output position vector

globalCount

void globalCount()
Collect global counts for traces/frames/volumes in sort order


main

public static void main(java.lang.String[] args)
                 throws SeisException
Parameters:
args -
Throws:
SeisException

sortAllocateMaps

void sortAllocateMaps()
                throws SeisException
Allocate memory and buffers for sort order maps

Throws:
SeisException

sortCreateMaps

void sortCreateMaps(int ntrc_est)
              throws SeisException
Create map files for a sort order

Parameters:
ntrc_est - estimated number of traces in sort
Throws:
SeisException

sortLocal

void sortLocal(SortMap[] list)
Loop through sort list and count traces, frames, and volumes


sortParallel

void sortParallel()
Parallel sort across tasks in a ParallelContext


sortWrite

void sortWrite()
         throws SeisException
Loop through sort list and write volume, frame, and trace maps

Throws:
SeisException - on map errors

totalFrames

long totalFrames(Seisio sio)
Calculate the total number of potential frames in an open JavaSeis dataset. Since JavaSeis datasets can be sparse, not all of the frames may exist.

Parameters:
sio - Seisio object for the JavaSeis dataset
Returns:
number of frames in the dataset

writeFrameMap

void writeFrameMap(int nfrm,
                   int ivol)
             throws SeisException
Write frame map for the current volume

Parameters:
nfrm - number of frames in the volume
ivol - volume index in the output sort order
Throws:
SeisException

writeTraceMap

void writeTraceMap(int ntrc,
                   int ivol,
                   int ifrm)
             throws SeisException
Write trace map for the current frame

Parameters:
ntrc - number of traces in the frame
ivol - volume index in the ouput sort order
ifrm - frame index within the current volume
Throws:
SeisException - on I/O errors

writeVolumeMap

void writeVolumeMap(int nvol,
                    int ivol)
              throws SeisException
Write volume map for a subrange of volumes

Parameters:
nvol - number of volumes in subrange
ivol - start index in output sort order for this subrange
Throws:
SeisException