Silly example of 4 node "Hello!" network.
authorTerry L. Wilmarth <wilmarth@uiuc.edu>
Tue, 25 Oct 2005 17:40:29 +0000 (17:40 +0000)
committerTerry L. Wilmarth <wilmarth@uiuc.edu>
Tue, 25 Oct 2005 17:40:29 +0000 (17:40 +0000)
examples/pose/MiniNet/Makefile [new file with mode: 0644]
examples/pose/MiniNet/Node.C [new file with mode: 0644]
examples/pose/MiniNet/Node.ci [new file with mode: 0644]
examples/pose/MiniNet/Node.h [new file with mode: 0644]
examples/pose/MiniNet/mininet.C [new file with mode: 0644]
examples/pose/MiniNet/mininet.ci [new file with mode: 0644]
examples/pose/MiniNet/mininet.h [new file with mode: 0644]

diff --git a/examples/pose/MiniNet/Makefile b/examples/pose/MiniNet/Makefile
new file mode 100644 (file)
index 0000000..96df019
--- /dev/null
@@ -0,0 +1,124 @@
+# NOTE: This is the basic Makefile template that includes the additional
+#       Makefile.simulation makefile that is found in the location of the
+#       current installation of POSE.
+#
+#      The Makefile.simulation set of rules allows the compilation of
+#       a SINGLE simulation module. If multiple simulation modules are
+#      desired, some "surgery" of Makefile.simulation (and this file)
+#      will be required. 
+#
+# ***********************************************************************
+
+OPTS=-O#-DCMK_OPTIMIZE=1 -DCMK_MEMCHECKS_OFF=1
+
+CHARMBASE=../../..
+CHARMBIN=$(CHARMBASE)/bin
+CHARMINC=$(CHARMBASE)/include
+
+CHARMC=$(CHARMBIN)/charmc -I$(CHARMINC)/pose $(OPTS)
+
+# Default Location variables
+# **************************
+#POSE_ROOT=$(HOME)/charm/net-linux/lib
+
+# Default module names
+# - MAKE MODIFICATIONS HERE
+# *************************
+PGM_MODULE=MiniNet
+PGM=mininet
+OTHER=
+LIBS=-Lstdc++ -lm
+
+# Simulation object definitions 
+# *****************************
+SIM_OBJECTS=Node_sim.o $(PGM).o 
+
+# EXECUTABLE GENERATION RULES 
+# - DO NOT MODIFY
+#****************************
+base:  $(PGM)
+       @echo "Simulation compiled."
+
+pure:   $(PGM).pure
+       @echo "Simulation (w purify) compiled."
+
+proj:   $(PGM).proj
+       @echo "Simulation (w projections log traces) compiled."
+
+summary:    $(PGM).summary
+       @echo "Simulation (w summary log traces) compiled."
+
+$(PGM):        $(SIM_OBJECTS) 
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM) \
+       -module pose -language charm++
+
+$(PGM).seq:    $(SIM_OBJECTS) 
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).seq \
+       -module seqpose -language charm++
+
+$(PGM).seq.proj:       $(SIM_OBJECTS) 
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).seq.proj \
+       -module seqpose -language charm++ -tracemode projections
+
+$(PGM).alt:    $(SIM_OBJECTS) 
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).alt \
+       -module pose -language charm++
+
+$(PGM).comm:   $(SIM_OBJECTS) 
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).comm \
+       -lpose -language charm++ -module commlib
+
+$(PGM).pure:   $(SIM_OBJECTS)
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).pure \
+       -lpose -language charm++ -purify
+
+$(PGM).proj:   $(SIM_OBJECTS)
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).proj \
+       -module pose -language charm++ -tracemode projections
+
+$(PGM).summary:        $(SIM_OBJECTS)
+       $(CHARMC) $(SIM_OBJECTS) $(OTHER) $(LIBS) -o $(PGM).summary \
+       -lpose -language charm++ -tracemode summary
+
+# HOUSE-KEEPING RULES
+# - DO NOT MODIFY
+#********************
+
+# clean removes everything
+clean: clear rm_logs ;
+
+# clear removes only binaries and generated files
+clear:
+       rm -f charmrun conv-host *.o
+       rm -f *.def.h *.decl.h
+       rm -f $(PGM) $(PGM).pure $(PGM).proj $(PGM).summary
+       rm -f gmon.out #*#
+       rm -f core *~
+       rm -f TAGS *.headers
+       rm -f *_sim.*
+
+# rm_logs removes projections/summary log traces
+rm_logs:
+       rm -f [^j]*.log *.sum [^j]*.sts
+       rm -f *-bg.*.log *-bg.sts
+
+# SIMULATION COMPILATION RULES
+# - DO NOT MODIFY 
+#*****************************
+$(PGM).o :     $(PGM).C $(PGM).h $(PGM_MODULE).def.h $(PGM_MODULE).decl.h
+       $(CHARMC) -c -I$(CHARMINC) $(INCLUDES) $(LIBS) $(PGM).C
+
+$(PGM_MODULE).def.h $(PGM_MODULE).decl.h : $(PGM).ci
+       $(CHARMC) $(INCLUDES) $(LIBS) $(PGM).ci
+
+Node_sim.o :   Node_sim.C Node_sim.h Node.def.h Node.decl.h
+       $(CHARMC) -c $(LIBS) $(INCLUDES) -I$(CHARMINC) Node_sim.C
+
+Node.def.h Node.decl.h : Node_sim.ci
+       $(CHARMC) $(INCLUDES) $(LIBS) Node_sim.ci
+
+Node_sim.C Node_sim.h Node_sim.ci: Node.C Node.h Node.ci 
+       $(CHARMBIN)/etrans.pl Node
+
+test:
+       ./pgm
diff --git a/examples/pose/MiniNet/Node.C b/examples/pose/MiniNet/Node.C
new file mode 100644 (file)
index 0000000..d1755f7
--- /dev/null
@@ -0,0 +1,65 @@
+Node::Node(nodeMsg *m)
+{
+  nbr1 = m->nbr1;
+  nbr2 = m->nbr2;
+  delete m;
+  transmitMsg *tm;
+  for (int i=0; i<4; i++) { // send to all other nodes
+    if (i != myHandle) { // don't send to self
+      tm = new transmitMsg;
+      tm->src = myHandle;
+      tm->dest = i;
+      strcpy(tm->data," Hello! ");
+      if (nbr1 == i) {
+       POSE_invoke(recv(tm), Node, nbr1, 3); // a hop takes 3 time units
+      }
+      else { // sends to nbr2 or non-nbr always go to nbr2
+       POSE_invoke(recv(tm), Node, nbr2, 3); // a hop takes 3 time units
+      }
+    }
+  }
+}
+
+Node::Node()
+{
+}
+
+Node& Node::operator=(const Node& obj)
+{
+  int i;
+  rep::operator=(obj);
+  nbr1 = obj.nbr1;
+  nbr2 = obj.nbr2;
+  return *this;
+}
+
+void Node::recv(transmitMsg *m)
+{
+  if (m->dest == myHandle) {
+    parent->CommitPrintf("%d received %s from %d at time %d\n", 
+                        myHandle, m->data, m->src, ovt);
+  }
+  else {
+    parent->CommitPrintf("%d forwarding message from %d to %d at time %d\n", 
+                        myHandle, m->src, m->dest, ovt);
+    transmitMsg *tm = new transmitMsg;
+    tm->src = m->src;
+    tm->dest = m->dest;
+    strcpy(tm->data, m->data);
+    if (nbr1 == tm->dest) { // sophisticated routing algorithm!
+      POSE_invoke(recv(tm), Node, nbr1, 3); // a hop takes 3 time units
+    }
+    else {
+      POSE_invoke(recv(tm), Node, nbr2, 3); // a hop takes 3 time units
+    }
+  }
+}
+
+void Node::recv_anti(transmitMsg *m)
+{
+  restore(this);
+}
+
+void Node::recv_commit(transmitMsg *m)
+{
+}
diff --git a/examples/pose/MiniNet/Node.ci b/examples/pose/MiniNet/Node.ci
new file mode 100644 (file)
index 0000000..8f44eeb
--- /dev/null
@@ -0,0 +1,12 @@
+message nodeMsg;
+message transmitMsg;
+
+poser Node : sim adapt4 chpt {
+  entry Node(nodeMsg *);
+  // Event methods
+  entry [event] void recv(transmitMsg *);
+};
+
+
+
+
diff --git a/examples/pose/MiniNet/Node.h b/examples/pose/MiniNet/Node.h
new file mode 100644 (file)
index 0000000..22c931e
--- /dev/null
@@ -0,0 +1,42 @@
+class nodeMsg {
+ public:
+  int nbr1, nbr2;
+  nodeMsg& operator=(const nodeMsg& obj) {
+    eventMsg::operator=(obj);
+    nbr1 = obj.nbr1;
+    nbr2 = obj.nbr2;
+    return *this;
+  }
+};
+
+class transmitMsg {
+ public:
+  int src, dest;
+  char data[30];
+  transmitMsg& operator=(const transmitMsg& obj) {
+    eventMsg::operator=(obj);
+    src = obj.src;
+    dest = obj.dest;
+    strcpy(data, obj.data);
+    return *this;
+  }
+};
+
+class Node {
+  int nbr1, nbr2;
+ public:
+  Node();
+  Node(nodeMsg *m); 
+  ~Node() { }
+  Node& operator=(const Node& obj);
+  void pup(PUP::er &p) { 
+    chpt<state_Node>::pup(p); 
+    p(nbr1); p(nbr2);
+  }
+
+  // Event methods
+  void recv(transmitMsg *m);
+  void recv_anti(transmitMsg *m);
+  void recv_commit(transmitMsg *m);
+};
+
diff --git a/examples/pose/MiniNet/mininet.C b/examples/pose/MiniNet/mininet.C
new file mode 100644 (file)
index 0000000..d51720b
--- /dev/null
@@ -0,0 +1,28 @@
+#include <unistd.h>
+#include <math.h>
+#include "pose.h"
+#include "mininet.h"
+#include "MiniNet.def.h"
+#include "Node_sim.h"
+
+main::main(CkArgMsg *m)
+{ 
+  CkGetChareID(&mainhandle);
+
+  POSE_init();
+
+  // create all the nodes
+  nodeMsg *nm;
+  for (int i=0; i<4; i++) {
+    nm = new nodeMsg;
+    // this mapping gives us:
+    // 0 --- 1
+    // |     |
+    // |     |
+    // 3 --- 2
+    nm->nbr1 = (i+1)%4;
+    nm->nbr2 = (i+3)%4;
+    nm->Timestamp(0);
+    (*(CProxy_Node *) &POSE_Objects)[i].insert(nm);
+  }
+}
diff --git a/examples/pose/MiniNet/mininet.ci b/examples/pose/MiniNet/mininet.ci
new file mode 100644 (file)
index 0000000..504134e
--- /dev/null
@@ -0,0 +1,8 @@
+mainmodule MiniNet {
+  extern module Node;
+  readonly CkChareID mainhandle;
+  
+  mainchare main {
+    entry main();
+  };
+};
diff --git a/examples/pose/MiniNet/mininet.h b/examples/pose/MiniNet/mininet.h
new file mode 100644 (file)
index 0000000..7e8b888
--- /dev/null
@@ -0,0 +1,9 @@
+#include "MiniNet.decl.h"
+
+CkChareID mainhandle;
+
+class main : public Chare {
+public:
+  main(CkArgMsg *m);
+  main(CkMigrateMessage *) {};
+};