A new liveViz Poll server which utilizes PythonCCS to generate images.
authorIsaac Dooley <idooley2@illinois.edu>
Thu, 18 Aug 2005 19:48:59 +0000 (19:48 +0000)
committerIsaac Dooley <idooley2@illinois.edu>
Thu, 18 Aug 2005 19:48:59 +0000 (19:48 +0000)
examples/charm++/lvServer/Makefile [new file with mode: 0644]
examples/charm++/lvServer/README.txt [new file with mode: 0644]
examples/charm++/lvServer/lvServer.C [new file with mode: 0644]
examples/charm++/lvServer/lvServer.ci [new file with mode: 0644]
examples/charm++/lvServer/run_server.sh [new file with mode: 0755]

diff --git a/examples/charm++/lvServer/Makefile b/examples/charm++/lvServer/Makefile
new file mode 100644 (file)
index 0000000..f2e1137
--- /dev/null
@@ -0,0 +1,22 @@
+LIBS = /usr/lib/python/config/libpython2.3.a -lpthread -lutil -ldl -lm
+
+CHARMC=charmc -module liveViz -module PythonCCS $(OPTS)
+
+OBJS = lvServer.o
+
+all: lvServer
+
+lvServer: $(OBJS)
+       $(CHARMC) -language charm++ -o lvServer $(OBJS) $(LIBS)
+
+lvServer.decl.h: lvServer.ci
+       $(CHARMC)  lvServer.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o lvServer charmrun *.log *.sum *.sts *~
+
+lvServer.o: lvServer.C lvServer.decl.h
+       $(CHARMC) -c lvServer.C
+
+test: all
+       charmrun ./lvServer +p5 ++server ++server-port 1234
diff --git a/examples/charm++/lvServer/README.txt b/examples/charm++/lvServer/README.txt
new file mode 100644 (file)
index 0000000..f42342a
--- /dev/null
@@ -0,0 +1,7 @@
+A simple liveViz poll server. Python commands will 
+cause images to be generated, while liveviz requests 
+will retrieve these server generated images.
+
+Use charm/java/bin/lvClient with this server.
+
+Author: Isaac Dooley 8-18-05
\ No newline at end of file
diff --git a/examples/charm++/lvServer/lvServer.C b/examples/charm++/lvServer/lvServer.C
new file mode 100644 (file)
index 0000000..2abab7e
--- /dev/null
@@ -0,0 +1,118 @@
+/*-------------------------------------------------------------
+ *  file   : lvServer.C
+ *  author : Isaac Dooley
+ *  date   : 08-18-05
+ *  
+ *  A sample LiveViz polling server application. Uses the new
+ *  poll mode interface.
+ *  
+ *  Use the corresponding lvClient java application. The server
+ *  in poll mode will not expect a ccs "lvConfig" request, so 
+ *  it will not work with other standard liveViz clients which 
+ *  are not in poll mode. This may change at some point in the 
+ *  future.
+ *  
+ *-------------------------------------------------------------*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "liveViz.h"
+#include "lvServer.decl.h"
+#include "math.h"
+
+int nChares=4;
+int gridWidth=400;  // image dimensions
+int gridHeight=400; // image dimensions
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ CProxy_lvServer arr;
+
+/*mainchare*/
+class Main : public CBase_Main
+{
+public:
+
+  Main(CkArgMsg* m)
+  {
+       delete m;
+       
+       CkPrintf("lvServer with %d slices on %d Processors\n", nChares, CkNumPes());
+       mainProxy=thishandle;
+       
+       // Register with python
+       mainProxy.registerPython("pycode");
+       
+       // Register with liveViz
+       liveVizPollInit();
+
+    // Create Array
+       CkArrayOptions opts(nChares);
+       arr = CProxy_lvServer::ckNew(opts);
+       CkPrintf("array has been created\n");
+
+       // At this point all chares are just idle until a liveViz message comes
+  } 
+
+
+  // can be called by client generated python
+  void pycall(int handle){
+       arr.genNextImage();
+       pythonReturn(handle);
+  }
+  
+};
+
+
+/*array [1D]*/
+class lvServer : public CBase_lvServer 
+{
+public:
+  lvServer(CkMigrateMessage *m) {}
+  lvServer() {}
+
+
+  void genNextImage() {
+       int myHeight = gridHeight / nChares;  // dimensions of my portion of the image
+    int myWidth = gridWidth;
+
+       int sx=0, sy=thisIndex*(myHeight);    // start coordinate(upper left corner) for my portion of the image
+
+    unsigned char *intensity= new unsigned char[3*myWidth*myHeight]; // the byte array that is my portion of the image
+
+       // Fill in the image byte array
+    for (int y=0;y<myHeight;y++)
+      for (int x=0;x<myWidth;x++) {
+       int i=y*myWidth+x;
+               if(thisIndex==0){
+                 intensity[3*i+0] = (byte) 128;//Red
+                 intensity[3*i+1] = (byte) 128;//Green
+                 intensity[3*i+2] = (byte) 128;//Blue
+               }
+               else if(thisIndex==1){
+                 intensity[3*i+0] = (byte) 0;//Red
+                 intensity[3*i+1] = (byte) 0;//Green
+                 intensity[3*i+2] = (byte) 0;//Blue
+               }
+               else{
+                 intensity[3*i+0] = (byte) 128;//Red
+                 intensity[3*i+1] = (byte) (128*thisIndex/nChares);//Green
+                 intensity[3*i+2] = (byte) (128*thisIndex/nChares);//Blue
+               }
+
+    }
+
+       // Deposit with liveViz
+       liveVizPollDeposit((ArrayElement *)this, 
+                                          sx,sy, 
+                                          myWidth,myHeight, 
+                                          gridWidth, gridHeight, 
+                                          (byte*) intensity,
+                                          sum_image_data, 3);
+
+       // cleanup
+    delete[] intensity;
+  }
+  
+};
+  
+#include "lvServer.def.h"
diff --git a/examples/charm++/lvServer/lvServer.ci b/examples/charm++/lvServer/lvServer.ci
new file mode 100644 (file)
index 0000000..3e2e264
--- /dev/null
@@ -0,0 +1,18 @@
+mainmodule lvServer {
+  readonly CProxy_Main mainProxy;
+  readonly int nChares;
+  readonly int gridWidth;
+  readonly int gridHeight;
+
+  mainchare [python] Main {
+    entry Main(CkArgMsg *m);
+       entry [python] void pycall(int handle);
+   };
+
+  array [1D] lvServer {
+    entry lvServer(void);
+       entry void genNextImage();
+ };
+
+
+};
diff --git a/examples/charm++/lvServer/run_server.sh b/examples/charm++/lvServer/run_server.sh
new file mode 100755 (executable)
index 0000000..f05b165
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+echo "Starting up server:"
+./charmrun +p2 ./lvServer ++server ++server-port 1234  $*
+echo "Server exited."