A simple portion of the library is working. Futures are added, but their return value...
authorIsaac Dooley <idooley2@illinois.edu>
Fri, 21 Apr 2006 20:34:59 +0000 (20:34 +0000)
committerIsaac Dooley <idooley2@illinois.edu>
Fri, 21 Apr 2006 20:34:59 +0000 (20:34 +0000)
examples/charm++/X10/Makefile
examples/charm++/X10/X10_lib.C
examples/charm++/X10/X10_lib.ci
examples/charm++/X10/X10_lib.h
examples/charm++/X10/X10_test2.C

index ef60a057bae35cf058a37e8d583666d7d1f812c1..1e5533ba4ecb4ad2d8975642e7256e7bab233f77 100644 (file)
@@ -16,4 +16,4 @@ X10_lib.o : X10_lib.C X10_lib.decl.h
 
 
 clean : 
-       rm -f a.out *~  X10_test2 charmrun X10_lib.o
+       rm -f a.out *~  X10_test2 charmrun X10_lib.o X10_lib.decl.h X10_lib.def.h
index 6dce84e451e705a36d5f8987542f0f41745c0a0e..410573898858424a974bd41268dc7fe8bc7bcb98 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <pup.h>
 #include <converse.h>
-#include "X10_test.decl.h"
+#include "X10_lib.decl.h"
 #include "X10_lib.h"
 
 
@@ -31,23 +31,22 @@ typedef CkVec<CkFutureID> *finishHandle;
 
 void *beginFinish(){
   CkVec<CkFutureID> *FinishFutureList = new CkVec<CkFutureID>;
+  CkAssert(FinishFutureList->size()==0);
   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);
+  //  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();
-       
+       len = FinishFutureList->length();       
   }
 
-  CkPrintf("MainThread: Future awaken\n");
+  //  CkPrintf("MainThread: Future awaken\n");
   delete FinishFutureList;
 }
 
@@ -55,15 +54,27 @@ 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);
+  //  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);
+  // CkPrintf("MainThread: Created Async call with handle %d\n", ftHandle);
 }
 
 
+FutureHandle futureCall(int place, int whichFunction, void *packedParams){
+  CkFutureID *fh = new CkFutureID;
+  asyncMsg *msg = new asyncMsg;
+  CkFutureID ftHandle = CkCreateAttachedFuture((void*)msg);
+  placesProxy[place].startFuture(whichFunction,ftHandle,CkMyPe());
+  return fh;
+}
+
+void * futureForce(FutureHandle fh){
+  asyncMsg *msg = (asyncMsg *)CkWaitFuture(*fh);
+  delete fh;
+  return NULL;  
+}
 
 
 
@@ -88,7 +99,7 @@ class Main : public CBase_Main
   }
   
   void libThread(){
-       CkPrintf("MainThread: executing in Main Chare\n");
+       //      CkPrintf("MainThread: executing in Main Chare\n");
        mainThread();   
        CkExit();
   }
@@ -105,8 +116,14 @@ public:
   
   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);
+       asnycHandler(whichStatement);
+       //      CkPrintf("Place %d: Finished async function, setting completion of Future [%d] \n", thisIndex, ftHandle);
+       CkSendToFuture(ftHandle, (void *)msg, pe_src);
+  }
+  
+  void startFuture(int whichStatement, CkFutureID ftHandle, int pe_src){
+       asyncMsg *msg = new asyncMsg;
+       futureHandler(whichStatement);
        CkSendToFuture(ftHandle, (void *)msg, pe_src);
   }
   
@@ -115,4 +132,4 @@ public:
 
 
   
-#include "X10_test.def.h"  
+#include "X10_lib.def.h"  
index 57b18a97b2e2a28673cc180a9c4131926b725e62..a162f1e6b4a09b7c2e77982848d541901274b2fb 100644 (file)
@@ -18,6 +18,7 @@ mainmodule X10_lib {
   array [1D] Places {
        entry void Places(void);
        entry [threaded] void startAsync(int which_statement, CkFutureID ftHandle, int pe_src);
+       entry [threaded] void startFuture(int which_statement, CkFutureID ftHandle, int pe_src);
   };
-
+  
 };  
index f657fa35664ab63505423928f6a06e0ba0e4f9dd..f2ebcdef8e883bccaba37be83c43e73049f4d64c 100644 (file)
@@ -7,10 +7,15 @@
 
 
 extern void mainThread(void);
-
+extern void asnycHandler(int whichStatement);
+extern void futureHandler(int whichStatement);
 
 typedef void* FinishHandle;
+typedef CkFutureID* FutureHandle;
 
-void *beginFinish();
+FinishHandle beginFinish();
 void endFinish(void *FinishFutureList);
 void asyncCall(void *FinishFutureList, int place, int whichFunction, void *packedParams);
+
+FutureHandle futureCall(int place, int whichFunction, void *packedParams);
+void *futureForce(FutureHandle);
index 54945003c88258dcacb84f9bc253fc7d4ce96411..366ef1b9f2e0eb04dbc12a065220db42e0b3f3c7 100644 (file)
@@ -8,19 +8,35 @@
 
 // Statements which can be executed by the application
 // These eventually will be created by a compiler
-void foo(){
-  printf("foo\n");
+
+void asnycHandler(int whichStatement){
+  printf("Faking execution of statement %d\n", whichStatement);
+}
+
+// Returning of data will probably be done via a serialized message. I would like to know
+// how the compiler folks would like to handle this.
+void futureHandler(int whichStatement){
+  printf("Faking execution of future %d\n", whichStatement);
 }
 
 
+
+
 void mainThread(){
   
   FinishHandle f = beginFinish();
-  
-  CkAssert(f);
-  asyncCall(f,1,1,NULL); // An X11 async method with place, whichFunction, and packed variables
-  foo();  // Do local work
-  
+  asyncCall(f,1,100,NULL); // An X11 async method with place, whichFunction, and packed variables  
+  printf("do some of my work here\n");;  // Do local work
+  asyncCall(f,2,101,NULL);
+  asyncCall(f,3,102,NULL);
+  asyncCall(f,2,103,NULL);
   endFinish(f);        //      Wait on async to finish
+
+  FutureHandle fut = futureCall(3, 2, NULL);  
+  futureForce(fut); // currently the return value is ignored, but once we choose the 
+                    // format for returning the data, it will be simple to add.
+  
+  printf("Done!\n");
+
 }