First Real version of application.
authorIsaac Dooley <idooley2@illinois.edu>
Fri, 21 Apr 2006 19:49:54 +0000 (19:49 +0000)
committerIsaac Dooley <idooley2@illinois.edu>
Fri, 21 Apr 2006 19:49:54 +0000 (19:49 +0000)
examples/charm++/X10/X10_lib.C [new file with mode: 0644]
examples/charm++/X10/X10_lib.ci [new file with mode: 0644]
examples/charm++/X10/X10_lib.h [new file with mode: 0644]
examples/charm++/X10/X10_test2.o [deleted file]

diff --git a/examples/charm++/X10/X10_lib.C b/examples/charm++/X10/X10_lib.C
new file mode 100644 (file)
index 0000000..6dce84e
--- /dev/null
@@ -0,0 +1,118 @@
+//-------------------------------------------------------------
+// file   : X10_test2.C
+// author : Isaac Dooley
+// date   : April 2006
+//
+
+#include <pup.h>
+#include <converse.h>
+#include "X10_test.decl.h"
+#include "X10_lib.h"
+
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ CProxy_Places placesProxy;
+/*readonly*/ int nPlaces;
+
+class asyncMsg : public CMessage_asyncMsg{
+ public:
+  int temp;
+  asyncMsg& operator=(const asyncMsg& obj) {
+       temp = obj.temp;
+    return *this;
+  }
+
+  asyncMsg(){temp=1;}
+
+};
+
+
+typedef CkVec<CkFutureID> *finishHandle;
+
+void *beginFinish(){
+  CkVec<CkFutureID> *FinishFutureList = new CkVec<CkFutureID>;
+  return (void*)FinishFutureList;
+} 
+
+void endFinish(void* ffl){
+  CkVec<CkFutureID> *FinishFutureList = (CkVec<CkFutureID> *)ffl;
+  int last = FinishFutureList->length();
+  CkPrintf("MainThread: Future waiting   last=%d\n", last);
+  int len = FinishFutureList->length();
+  while(len > 0){
+       CkPrintf("len=%d\n", len);
+       asyncMsg *msg = (asyncMsg *)CkWaitFuture((*FinishFutureList)[len-1]);
+       FinishFutureList->remove(len-1);
+       len = FinishFutureList->length();
+       
+  }
+
+  CkPrintf("MainThread: Future awaken\n");
+  delete FinishFutureList;
+}
+
+void asyncCall(void *ffl, int place, int whichFunction, void *packedParams){
+  CkVec<CkFutureID> * FinishFutureList = (CkVec<CkFutureID> *)ffl;
+  asyncMsg *msg = new asyncMsg;
+  CkFutureID ftHandle = CkCreateAttachedFuture((void*)msg);
+  CkAssert(FinishFutureList->size()==0);
+  FinishFutureList->push_back(ftHandle);
+  CkPrintf("MainThread: Created Future with handle %d\n", ftHandle);
+  (*FinishFutureList)[FinishFutureList->length()]=ftHandle;
+  placesProxy[place].startAsync(whichFunction,ftHandle,CkMyPe());
+  CkPrintf("MainThread: Created Async call with handle %d\n", ftHandle);
+}
+
+
+
+
+
+/*mainchare*/
+class Main : public CBase_Main
+{
+ public:
+
+  Main(CkArgMsg* m)
+  {
+       nPlaces=CkNumPes();
+       CkPrintf("Starting Up: %d Places(Processors)\n", nPlaces);  
+       mainProxy = thishandle;
+
+       CkAssert(nPlaces >= 2);
+
+    // Create X10 Places       
+       placesProxy = CProxy_Places::ckNew(nPlaces);
+
+       mainProxy.libThread();
+
+  }
+  
+  void libThread(){
+       CkPrintf("MainThread: executing in Main Chare\n");
+       mainThread();   
+       CkExit();
+  }
+  
+};
+
+/*mainchare*/
+class Places : public CBase_Places
+{
+public:
+  
+  Places(CkMigrateMessage *m){}
+  Places(){}
+  
+  void startAsync(int whichStatement, CkFutureID ftHandle, int pe_src){
+       asyncMsg *msg = new asyncMsg;
+       CkPrintf("Place %d: faking execution of statement %d\n", thisIndex, whichStatement);
+       CkPrintf("Place %d: Finished work, sending result to Future [%d] \n", thisIndex, ftHandle);
+       CkSendToFuture(ftHandle, (void *)msg, pe_src);
+  }
+  
+};
+
+
+
+  
+#include "X10_test.def.h"  
diff --git a/examples/charm++/X10/X10_lib.ci b/examples/charm++/X10/X10_lib.ci
new file mode 100644 (file)
index 0000000..57b18a9
--- /dev/null
@@ -0,0 +1,23 @@
+
+mainmodule X10_lib {
+
+  message asyncMsg;
+
+  /*  extern module CkFutures;*/
+
+  readonly CProxy_Main mainProxy;
+  readonly int nPlaces;
+  readonly CProxy_Places placesProxy;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);            // cannot be threaded
+       entry [threaded] void libThread();
+  };
+  
+
+  array [1D] Places {
+       entry void Places(void);
+       entry [threaded] void startAsync(int which_statement, CkFutureID ftHandle, int pe_src);
+  };
+
+};  
diff --git a/examples/charm++/X10/X10_lib.h b/examples/charm++/X10/X10_lib.h
new file mode 100644 (file)
index 0000000..f657fa3
--- /dev/null
@@ -0,0 +1,16 @@
+// X10_lib.h
+
+#include <pup.h>
+#include <converse.h>
+#include <charm++.h>
+
+
+
+extern void mainThread(void);
+
+
+typedef void* FinishHandle;
+
+void *beginFinish();
+void endFinish(void *FinishFutureList);
+void asyncCall(void *FinishFutureList, int place, int whichFunction, void *packedParams);
diff --git a/examples/charm++/X10/X10_test2.o b/examples/charm++/X10/X10_test2.o
deleted file mode 100644 (file)
index 41a41f0..0000000
Binary files a/examples/charm++/X10/X10_test2.o and /dev/null differ