SHARE
TWEET

Untitled

a guest Feb 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <upcxx/upcxx.hpp>
  2. #include <thread>
  3. #include <stdio.h>
  4. #include <assert.h>
  5.  
  6. using namespace std;
  7.  
  8. struct Data {
  9.     int data;
  10.     bool done;
  11.     Data(int d, bool b) : data(d), done(b) {};
  12. };
  13. using dobj_d_t = upcxx::dist_object<Data*>;
  14.  
  15. int main(int argc, char** argv)
  16. {
  17.     upcxx::init();
  18.     int N = atoi(argv[1]);
  19.     cout << "Running " << N << " times" << endl;
  20.     Data* data = new Data(-1, false);
  21.     dobj_d_t local_d(data);
  22.     const int n_ranks = upcxx::rank_n();
  23.     const int rank    = upcxx::rank_me();
  24.     int dest          = (rank + 1) % n_ranks;
  25.     int expected      = rank;
  26.  
  27.     upcxx::liberate_master_persona();
  28.  
  29.     for(int n = 0; n < N; n++) {
  30.        
  31.         (*data) = Data(-1, false);
  32.  
  33.         thread tc = thread([&](){
  34.             upcxx::persona_scope scope(upcxx::master_persona());
  35.             printf("Comm %d started -> %d\n", rank, dest);
  36.             upcxx::rpc_ff(dest,
  37.                 [](dobj_d_t &data, int payload) {
  38.                     printf("Rank %d received RPC, data is at %p\n", upcxx::rank_me(), *data);
  39.                     (*data)->data = payload;
  40.                     (*data)->done = true;
  41.                     printf("Rank %d received data %d\n", upcxx::rank_me(), payload);
  42.                 },
  43.                 local_d, dest);
  44.             printf("Comm %d done\n", rank);
  45.             while(! data->done) {
  46.                 upcxx::progress();
  47.             }
  48.             printf("Progress %d done\n", rank);
  49.         });
  50.  
  51.         tc.join();
  52.  
  53.         if(data->data == expected) {
  54.             printf("SUCCESS\n");
  55.         } else {
  56.             printf("FAILED\n");
  57.         }
  58.        
  59.     }
  60.  
  61.     upcxx::persona_scope scope(upcxx::master_persona());
  62.     upcxx::barrier();
  63.     upcxx::finalize();
  64.     delete data;
  65.     return 0;
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top