#include <stdlib.h>
#include
#include
#include <ray/api.h>
#include
using namespace std;
#define DATAGB 1
const size_t dataSize = DATAGB10241024300; //102410241024
char transfer_data(std::vector obj)
{
char stat = obj[0] + obj[1];
return stat;
}
// 声明为远程函数
RAY_REMOTE(transfer_data);
int main(int argc, char **argv)
{
ray::Init();
std::vector arr(dataSize, 10);
for(int i=0;i<100;i++)
{
chrono::steady_clock::time_point beforeTime = std::chrono::steady_clock::now();
auto task_object_arr = ray::Put(arr);
auto task_object = ray::Task(transfer_data).Remote(task_object_arr);
auto task_result = *(ray::Get(task_object));
chrono::steady_clock::time_point afterTime = std::chrono::steady_clock::now();
auto duration_millsecond = std::chrono::duration<double, std::milli>(afterTime - beforeTime).count();
float duration_second = duration_millsecond /1000.0;
float dataSizeGB = dataSize/1024.0/1024.0/1024.0;
printf("Transfer: %f GB , cost:%.2f seconds, bandwidth = %.2fGbps \n",dataSizeGB, duration_second, dataSizeGB/duration_second*8);
}
ray::Shutdown();
}
代码如上