add pingpong example
authorXiang Ni <xiangni2@illinois.edu>
Wed, 29 Feb 2012 17:22:33 +0000 (11:22 -0600)
committerXiang Ni <xiangni2@illinois.edu>
Wed, 29 Feb 2012 17:22:33 +0000 (11:22 -0600)
doc/converse/code/pingpong.pseudo [new file with mode: 0644]
doc/converse/tutorial.tex

diff --git a/doc/converse/code/pingpong.pseudo b/doc/converse/code/pingpong.pseudo
new file mode 100644 (file)
index 0000000..d7ebc29
--- /dev/null
@@ -0,0 +1,58 @@
+CpvDeclare(int,msgSize);
+CpvDeclare(int,exitHandler);
+CpvDeclare(int,node0Handler);
+CpvDeclare(int,node1Handler);
+void startRing()
+{
+  char *msg = (char *)CmiAlloc(CpvAccess(msgSize));
+  *((int *)(msg+CmiMsgHeaderSizeBytes)) = CpvAccess(msgSize);
+  CmiSetHandler(msg,CpvAccess(node1Handler));
+  CmiSyncSendAndFree(1, CpvAccess(msgSize), msg);
+}
+void ringFinished(char *msg)
+{
+  CmiFree(msg);
+  //exit
+  void *sendmsg = CmiAlloc(CmiMsgHeaderSizeBytes);
+  CmiSetHandler(sendmsg,CpvAccess(exitHandler));
+  CmiSyncBroadcastAllAndFree(CmiMsgHeaderSizeBytes,sendmsg);
+}
+//We finished for all message sizes. Exit now
+CmiHandler exitHandlerFunc(char *msg)
+{
+    CmiFree(msg);
+    CsdExitScheduler();
+    return 0;
+}
+//Handler on Node 0
+CmiHandler node0HandlerFunc(char *msg)
+{
+        ringFinished(msg);
+               return 0;
+}
+CmiHandler node1HandlerFunc(char *msg)
+{
+    CpvAccess(msgSize) = *((int *)(msg+CmiMsgHeaderSizeBytes));
+    CmiSetHandler(msg,CpvAccess(node0Handler));
+    CmiSyncSendAndFree(0,CpvAccess(msgSize),msg);
+    return 0;
+}
+CmiStartFn mymain()
+{
+    CpvInitialize(int,msgSize);
+    CpvAccess(msgSize)= 512 + CmiMsgHeaderSizeBytes;
+    CpvInitialize(int,exitHandler);
+    CpvAccess(exitHandler) = CmiRegisterHandler((CmiHandler) exitHandlerFunc);
+    CpvInitialize(int,node0Handler);
+    CpvAccess(node0Handler) = CmiRegisterHandler((CmiHandler) node0HandlerFunc);
+    CpvInitialize(int,node1Handler);
+    CpvAccess(node1Handler) = CmiRegisterHandler((CmiHandler) node1HandlerFunc);
+    if (CmiMyPe() == 0)
+        startRing();
+    return 0;
+}
+int main(int argc,char *argv[])
+{
+    ConverseInit(argc,argv,(CmiStartFn)mymain,0,0);
+    return 0;
+}
index 564cbd21c55d032101c4961f4bdbf1400a795c19..5c4e1e50d213f143b879ec61d1621ce191754c2d 100644 (file)
@@ -13,5 +13,16 @@ Urbana-Champaign.
 \maketitle
 
 \chapter{Introduction}
+\lstdefinelanguage{pseudo}{
+morekeywords={if, else, for, in, remove, from, case, do, forever, to, False, True},
+sensitive=true,%
+morecomment=[l]\#,%
+morestring=[b]',%
+}
+\begin{figure}
+\lstinputlisting[language=pseudo,basicstyle=\small,numbers=left,escapechar=\%]{code/pingpong.pseudo}
+\caption{A Pingpong Example using Converse Handler}
+\label{fig:converse-pingpong}
+\end{figure}
 
-\end{document}
\ No newline at end of file
+\end{document}