Advertisement
alexsetyaev

contest

Oct 1st, 2021
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. double t_start = omp_get_wtime();
  2. // запускаем копирования данных
  3. GraphCSR gpu_graph[2];
  4. t1 = omp_get_wtime();
  5. #pragma omp parallel num_threads(2)
  6. {
  7. int tid = omp_get_thread_num();
  8. cudaSetDevice(tid);
  9. user_copy_graph_to_device(csr_graph, gpu_graph[tid]);
  10. }
  11. t2 = omp_get_wtime();
  12. cout << "Device->host copy time: " << t2 - t1 << " sec" << endl;
  13.  
  14. // запускаем алгоритм
  15. cudaDeviceSynchronize();
  16. t1 = omp_get_wtime();
  17. int last_source = 0;
  18. cout << "will do " << iterations << " iterations" << endl;
  19. #pragma omp parallel for shared(last_source)
  20. for(int i = 0; i < iterations; i++)
  21. {
  22.  
  23. int tid = omp_get_thread_num();
  24. int current_gpu = tid%2;
  25. cudaSetDevice(current_gpu);
  26. int source_vertex = rand() % graph.vertices_count;
  27. int *local_result = new int[graph.vertices_count];
  28. user_algorithm(gpu_graph[current_gpu], local_result, source_vertex);
  29. if (i == (iterations - 1)){
  30. memcpy(user_result, local_result, n * sizeof(int)*graph.vertices_count);
  31. last_source = source_vertex;
  32. }
  33. delete []local_result;
  34.  
  35. }
  36. cudaDeviceSynchronize();
  37. t2 = omp_get_wtime();
  38. double t_end = omp_get_wtime();
  39. cout << "BFS wall time: " << t2 - t1 << " sec" << endl;
  40.  
  41. free_memory(&gpu_graph);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement