*** empty log message ***
[charm.git] / doc / libraries / liveviz.tex
blob234684d30ab3c3d00b72439501c35ef09fdf0954
1 \section{Introduction}
3 If array elements compute a small piece of a large 2D image, then these
4 image chunks can be combined across processors to form one large
5 image using the liveViz library. In other
6 words, liveViz provides a way to reduce 2D-image data, which
7 combines small chunks
8 of images deposited by chares into one large image.
10 This visualization library follows the client server model.
11 The server, a parallel Charm++ program, does all image assembly,
12 and opens a network (CCS) socket which clients use to request and
13 download images. The client is a small Java program.
14 A typical use of this is:
15 \begin{alltt}
16 cd charm/pgms/charm++/ccs/liveViz/server
17 make
18 ./charmrun ./pgm +p2 ++server ++server-port 1234 &
19 ~/charm/bin/liveViz localhost 1234
20 \end{alltt}
24 \section{How to use liveViz with \charmpp{} program}
26 The liveViz routines are in the Charm++ header ``liveViz.h''.
28 A typical program provides a chare array with one entry method
29 with the following prototype:
31 \begin{alltt}
32 entry void functionName(liveVizRequestMsg *m);
33 \end{alltt}
35 This entry method is supposed to deposit its (array element's) chunk of
36 the image. This entry method has following structure:
38 \begin{alltt}
39 void myArray::functionName (liveVizRequestMsg *m)
41 // prepare image chunk
42 ...
44 liveVizDeposit (m, startX, startY, width, height, imageBuff, this);
46 // delete image buffer if it was dynamically allocated
48 \end{alltt}
50 Here, ``width'' and ``height'' are the size, in pixels, of this array
51 element's portion of the image, contributed in ``imageBuff'' (described below).
52 This will show up on the client's assembled image at 0-based pixel
53 (startX,startY). The client's display width and height are stored
54 in m->req.wid and m->req.ht.
56 By default liveViz combines image chunks by doing a saturating sum of
57 overlapping pixel values. If you want liveViz to combine image chunks by using
58 max (i.e. for overlapping pixels in deposited image chunks, final image will
59 have the pixel with highest intensity or in other words largest value), you need
60 to pass one more parameter (liveVizCombine\_t) to the ``liveVizDeposit'' function:
62 \begin{alltt}
63 liveVizDeposit (m, startX, startY, width, height, imageBuff, this,
64 max\_image\_data);
65 \end{alltt}
67 You can also reduce floating-point image data using
68 sum\_float\_image\_data or max\_float\_image\_data.
71 \section{Format of deposit image}
73 ``imageBuff'' is run of bytes representing a rectangular portion
74 of the image. This buffer represents image using a row-major format,
75 so 0-based pixel (x,y) (x increasing to the right, y increasing downward
76 in typical graphics fashion) is stored at array offset ``x+y*width''.
78 If the image is gray-scale (as determined by liveVizConfig, below), each pixel
79 is represented by one byte. If the image is color, each pixel is represented
80 by 3 consecutive bytes representing red, green, and blue intensity.
82 If the image is floating-point, each pixel is represented by a single
83 `float', and after assembly colorized by calling the user-provided
84 routine below. This routine converts fully assembled `float' pixels
85 to RGB 3-byte pixels, and is called only on processor 0 after each
86 client request.
88 \begin{alltt}
89 extern "C"
90 void liveVizFloatToRGB(liveVizRequest &req,
91 const float *floatSrc, unsigned char *destRgb,
92 int nPixels);
93 \end{alltt}
96 \section{liveViz Initialization}
98 liveViz library needs to be initialized before it can be used for
99 visualization. For initialization follow the following steps
100 from your main chare:
102 \begin{enumerate}
103 \item Create your chare array (array proxy object 'a') with the entry
104 method 'functionName' (described above).
105 \item Create a CkCallback object ('c'), specifying 'functionName' as the
106 callback function. This callback will be invoked whenever the
107 client requests a new image.
108 \item Create a liveVizConfig object ('cfg'). LiveVizConfig takes a number
109 of parameters, as described below.
110 \item Call liveVizInit (cfg, a, c).
111 \end{enumerate}
113 The liveVizConfig parameters are:
114 \begin{itemize}
115 \item The first parameter is the pixel type to be reduced:
116 \begin{itemize}
117 \item ``false'' or liveVizConfig::pix\_greyscale means a greyscale image (1 byte per pixel).
118 \item ``true'' or liveVizConfig::pix\_color means a color image (3 RGB bytes per pixel).
119 \item liveVizConfig::pix\_float means a floating-point color image (1 float per pixel, can only be used with sum\_float\_image\_data or max\_float\_image\_data).
120 \end{itemize}
121 \item The second parameter is the flag ``serverPush'', which is passed to the client application. If set to true, the client will repeatedly request for images. When set to false the client will only request for images when its window is resized and needs to be updated.
122 \item The third parameter is an optional 3D bounding box (type CkBbox3d). If present, this puts the client into a 3D visualization mode.
123 \end{itemize}
125 A typical 2D, RGB, non-push call to liveVizConfig looks like this:
126 \begin{alltt}
127 liveVizConfig cfg(true,false);
128 \end{alltt}
130 \section{Compilation}
132 A \charmpp{} program that uses liveViz must be linked with '-module liveViz'.
134 Before compiling a liveViz program, the liveViz library may need to be compiled.
135 To compile the liveViz library:
136 \begin{itemize}
137 \item go to .../charm/tmp/libs/ck-libs/liveViz
138 \item make
139 \end{itemize}
142 \section{Poll Mode}
144 In some cases you may want a server to deposit images only when it is ready to do so.
145 For this case the server will not register a callback function that triggers image generation, but rather the server will deposit an image at its convenience.
146 For example a server may want to create a movie or series of images corresponding to some
147 timesteps in a simulation. The server will have a timestep loop in which an array computes
148 some data for a timestep. At the end of each iteration the server will deposit the image. The use of LiveViz's Poll Mode supports this type of server generation of images.
150 Poll Mode contains a few significant differences to the standard mode. First we describe the use of Poll Mode, and then we will describe the differences. liveVizPoll must get control during the creation of your array,
151 so you call liveVizPollInit with no parameters.
153 \begin{alltt}
154 liveVizPollInit();
155 CkArrayOptions opts(nChares);
156 arr = CProxy_lvServer::ckNew(opts);
157 \end{alltt}
159 To deposit an image, the server just calls liveVizPollDeposit. The server must take care not to generate too many images, before a client requests them. Each server generated image is buffered until the client can get the image. The buffered images will be stored in memory on processor 0.
161 \begin{alltt}
162 liveVizPollDeposit( this,
163 startX,startY, // Location of local piece
164 localSizeX,localSizeY, // Dimensions of the piece I'm depositing
165 globalSizeX,globalSizeY, // Dimensions of the entire image
166 img, // Image byte array
167 sum_image_data, // Desired image combiner
168 3 // Bytes/pixel
170 \end{alltt}
171 The last two parameters are optional. By default they are set to sum\_image\_data and 3 bytes per pixel.
175 A sample liveVizPoll server and client are available at:
176 \begin{alltt}
177 .../charm/examples/charm++/lvServer
178 .../charm/java/bin/lvClient
179 \end{alltt}
180 This example server uses a PythonCCS command to cause an image to be generated by the server. The client also then gets the image.
182 LiveViz provides multiple image combiner types. Any supported type can be used as a parameter to liveVizPollDeposit. Valid combiners include: sum\_float\_image\_data, max\_float\_image\_data, sum\_image\_data, and max\_image\_data.
184 The differences in Poll Mode may be apparent. There is no callback function which causes the server to generate and deposit an image. Furthermore, a server may generate an image before or after a client has sent a request. The deposit function, therefore is more complicated, as the server will specify information about the image that it is generating. The client will no longer specify the desired size or other configuration options, since the server may generate the image before the client request is available to the server. The liveVizPollInit call takes no parameters.
186 The server should call Deposit with the same global size and combiner type on all of the array elements which correspond to the ``this'' parameter.
188 The latest version of liveVizPoll is not backwards compatable with older versions. The old version had some fundamental problems which would occur if a server generated an image before a client requested it. Thus the new version buffers server generated images until requested by a client. Furthermore the client requests are also buffered if they arrive before the server generates the images. Problems could also occur during migration with the old version.