- changed title to simple code with rpc/rget/rput
- edited description
simple code with rpc/rget/rput
I want to test a array with 10 elements. I want to receive a new array with double values. first = [0,1,2,3,4,5,6,7,8,9]
The final values is: 0 2 4 6 8 10 12 14 16 18
#include <upcxx/upcxx.hpp>
#include <iostream>
using namespace std;
int double_num(int num)
{
cout<<"process: "<<upcxx::rank_me()<<endl;
return num*2;
}
int main(int argc, char **argv)
{
upcxx::global_ptr<int> first =upcxx::new_<int>(10);
int*x = first.local();
for(int i=0; i<10; i++)
{
x[i]=i;
}
upcxx::init(); //start upc++
upcxx::future<int> f1= upcxx::rget(first);
upcxx::future<int> f2= f1.then(double_num);
f2.wait();
upcxx::finalize(); //end upc++
cout<<"Results: "<<endl;
x = first.local();
for(int i=0; i<10; i++)
{
cout << x[i]<<" ";
}
upcxx::delete_(first);
return 0;
}
Results: Segmentation fault
Please help me to figure out how to change in this code?
Thanks,
Comments (4)
-
reporter -
reporter - edited description
-
- changed status to invalid
Hi Ngoc-
upcxx::new_ and upcxx::delete_ must be called while the library is initialized, between init and finalize, which is likely the cause of your crash. Also, I highly recommend developing in debug mode (
upcxx -g
and/orUPCXX_CODEMODE=debug
), which enables assertion checks for many such mistakes.Once that's fixed, I don't think this program does what you expect. First, there is no real communication in this program. Every rank is allocating its own array and then reading a copy of the first element, and then doubling that value, which is placed into f2.result(). However nothing after the initialization loop is writing to the array, so there's no reason to expect those values to change.
I highly recommend reading the Programmer's Guide for an introduction to UPC++ programming.
Hope this helps...
-
reporter - changed status to closed
- Log in to comment