ZC Direct API: Add an example with an immediate entry method callback 56/4656/4
authorNitin Bhat <nbhat4@illinois.edu>
Fri, 5 Oct 2018 02:40:54 +0000 (22:40 -0400)
committerNitin Bhat <nbhat4@illinois.edu>
Mon, 8 Oct 2018 21:23:01 +0000 (16:23 -0500)
Change-Id: I54a01e466c311c756122fd81bb84fb13ff7f8160

examples/charm++/zerocopy/direct_api/Makefile
examples/charm++/zerocopy/direct_api/misc/Makefile [new file with mode: 0644]
examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/Makefile [new file with mode: 0644]
examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.C [new file with mode: 0644]
examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.ci [new file with mode: 0644]

index dc0558e334981c69c69b6b2c4658731234415257..4cc65d57535128690450183b0f338401a1a58c4e 100644 (file)
@@ -2,6 +2,7 @@ DIRS = \
   unreg \
   prereg \
   reg \
+  misc \
 
 TESTDIRS = $(DIRS)
 
diff --git a/examples/charm++/zerocopy/direct_api/misc/Makefile b/examples/charm++/zerocopy/direct_api/misc/Makefile
new file mode 100644 (file)
index 0000000..96dae3e
--- /dev/null
@@ -0,0 +1,21 @@
+DIRS = \
+  zcpy_immediate \
+
+TESTDIRS = $(DIRS)
+
+all: $(foreach i,$(DIRS),build-$i)
+
+test: $(foreach i,$(TESTDIRS),test-$i)
+
+clean: $(foreach i,$(DIRS),clean-$i)
+       rm -f TAGS #*#
+       rm -f core *~
+
+$(foreach i,$(DIRS),build-$i):
+       $(MAKE) -C $(subst build-,,$@) all OPTS='$(OPTS)'
+
+$(foreach i,$(DIRS),test-$i):
+       $(MAKE) -C $(subst test-,,$@) test OPTS='$(OPTS)' TESTOPTS='$(TESTOPTS)'
+
+$(foreach i,$(DIRS),clean-$i):
+       $(MAKE) -C $(subst clean-,,$@) clean OPTS='$(OPTS)'
diff --git a/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/Makefile b/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/Makefile
new file mode 100644 (file)
index 0000000..fbaf0c1
--- /dev/null
@@ -0,0 +1,23 @@
+-include ../../../../../common.mk
+CHARMC=../../../../../../bin/charmc $(OPTS)
+
+all: zcpy_immediate
+
+OBJS = zcpy_immediate.o
+
+zcpy_immediate: $(OBJS)
+       $(CHARMC) -language charm++ -o zcpy_immediate $(OBJS)
+
+cifiles: zcpy_immediate.ci
+       $(CHARMC)  zcpy_immediate.ci
+       touch cifiles
+
+zcpy_immediate.o: zcpy_immediate.C cifiles
+       $(CHARMC) -c zcpy_immediate.C
+
+test: all
+       $(call run, +p1 ./zcpy_immediate 20 )
+       $(call run, +p2 ./zcpy_immediate 20 )
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o zcpy_immediate charmrun cifiles
diff --git a/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.C b/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.C
new file mode 100644 (file)
index 0000000..1b13073
--- /dev/null
@@ -0,0 +1,126 @@
+#include "zcpy_immediate.decl.h"
+
+CProxy_main mainProxy;
+CProxy_NG1 ngProxy;
+int numElements;
+
+class main : public CBase_main
+{
+  CProxy_Array1 arr1;
+  int count;
+public:
+  main(CkMigrateMessage *m) {}
+  main(CkArgMsg *m)
+  {
+    if(m->argc !=2 ) {
+      CkPrintf("Usage: ./zcpy_immediate <numelements>\n");
+      CkExit(1);
+    }
+    numElements = atoi(m->argv[1]);
+    delete m;
+    if(numElements % 2 != 0){
+      CkPrintf("Argument <numelements> should be even");
+      CkExit(1);
+    }
+    mainProxy = thisProxy;
+    ngProxy = CProxy_NG1::ckNew();
+    int size = 2000;
+    arr1 = CProxy_Array1::ckNew(size, numElements);
+    count = 0;
+    arr1.start();
+  };
+
+  void maindone(){
+    count++;
+    if(count == numElements*2) {
+      CkPrintf("[%d][%d][%d] All Rgets have completed\n", CkMyPe(), CkMyNode(), CmiMyRank());
+      CkExit();
+    }
+  };
+};
+
+void assignCharValues(char *&arr, int size){
+  arr = new char[size];
+  for(int i=0; i<size; i++)
+     arr[i] = (char)(rand() % 125 + 1);
+}
+
+class Array1 : public CBase_Array1
+{
+  char *cArr1, *cArr2;
+  int size;
+  CkCallback srcCb, destCb;
+  int destIndex;
+
+public:
+  Array1(int size)
+  {
+    this->size = size;
+
+    if(thisIndex < numElements/2) {
+      assignCharValues(cArr1, size); // cArr1 is the source for Get
+      cArr2 = new char[size]; // cArr2 is the destination for Put
+    } else {
+      cArr1 = new char[size]; // cArr1 is the destination for Get
+      assignCharValues(cArr2, size); // cArr2 is the source for Put
+    }
+
+    srcCb = CkCallback(CkIndex_NG1::senderDone(NULL), ngProxy[CkMyNode()]);
+    destCb = CkCallback(CkIndex_NG1::receiverDone(NULL), ngProxy[CkMyNode()]);
+
+    destIndex = numElements - 1 - thisIndex;
+  }
+
+  void start()
+  {
+    if(thisIndex < numElements/2) {
+      CkNcpyBuffer mySrc(cArr1, size*sizeof(char), srcCb, CK_BUFFER_REG);
+      CkNcpyBuffer myDest(cArr2, size*sizeof(char), destCb, CK_BUFFER_UNREG);
+
+      // Send my source & my destination to destIndex
+      // Index 1 performs get from my source and performs put into my destination
+      thisProxy[destIndex].recvNcpyInfo(mySrc, myDest);
+    }
+  }
+
+  // Executed on Index 1
+  void recvNcpyInfo(CkNcpyBuffer otherSrc, CkNcpyBuffer otherDest)
+  {
+    // Create nocopy destination for me to Get into
+    CkNcpyBuffer myDest(cArr1, size*sizeof(char), destCb, CK_BUFFER_UNREG);
+    // Create nocopy source for me to Put from
+    CkNcpyBuffer mySrc(cArr2, size*sizeof(char), srcCb, CK_BUFFER_REG);
+
+    // Perform Get from other source into my destinations
+    myDest.get(otherSrc);
+
+    // Perform Put from my source into other destinations
+    mySrc.put(otherDest);
+  }
+};
+
+class NG1 : public CBase_NG1 {
+  public:
+  NG1() {}
+
+  void senderDone(CkDataMsg *m){
+    // Cast m->data as (CkNcpyBuffer *)
+    CkNcpyBuffer *src = (CkNcpyBuffer *)(m->data);
+    src->deregisterMem();
+    delete m;
+
+    mainProxy.maindone();
+  }
+
+  // Executed on Index 1 (which receives data from get)
+  void receiverDone(CkDataMsg *m){
+    // Cast m->data as (CkNcpyBuffer *)
+    CkNcpyBuffer *dest = (CkNcpyBuffer *)(m->data);
+    dest->deregisterMem();
+    delete m;
+
+    mainProxy.maindone();
+  }
+};
+
+#include "zcpy_immediate.def.h"
diff --git a/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.ci b/examples/charm++/zerocopy/direct_api/misc/zcpy_immediate/zcpy_immediate.ci
new file mode 100644 (file)
index 0000000..697289a
--- /dev/null
@@ -0,0 +1,23 @@
+mainmodule zcpy_immediate{
+
+  readonly CProxy_main mainProxy;
+  readonly CProxy_NG1 ngProxy;
+  readonly int numElements;
+
+  mainchare main {
+    entry main(CkArgMsg *m);
+    entry void maindone();
+  };
+
+  array [1D] Array1 {
+    entry Array1(int size);
+    entry void start();
+    entry void recvNcpyInfo(CkNcpyBuffer otherSrc, CkNcpyBuffer otherDest);
+  };
+
+  nodegroup NG1 {
+    entry NG1();
+    entry [immediate] void senderDone(CkDataMsg *m);
+    entry [immediate] void receiverDone(CkDataMsg *m);
+  };
+};