Skip to content

Commit 8e8cad2

Browse files
authored
Fix: compile cuda without openmp (#5488)
1 parent dcff74d commit 8e8cad2

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

source/module_hamilt_lcao/module_gint/gint_force_gpu.cu

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef _OPENMP
12
#include <omp.h>
3+
#endif
24

35
#include "gint_force_gpu.h"
46
#include "kernels/cuda/cuda_tools.cuh"
@@ -87,16 +89,21 @@ void gint_fvl_gpu(const hamilt::HContainer<double>* dm,
8789
dm->get_wrapper(),
8890
dm->get_nnr() * sizeof(double),
8991
cudaMemcpyHostToDevice));
90-
92+
#ifdef _OPENMP
9193
#pragma omp parallel for num_threads(num_streams) collapse(2)
94+
#endif
9295
for (int i = 0; i < gridt.nbx; i++)
9396
{
9497
for (int j = 0; j < gridt.nby; j++)
9598
{
9699
// 20240620 Note that it must be set again here because
97100
// cuda's device is not safe in a multi-threaded environment.
98101
checkCuda(cudaSetDevice(gridt.dev_id));
102+
#ifdef _OPENMP
99103
const int sid = omp_get_thread_num();
104+
#else
105+
const int sid = 0;
106+
#endif
100107

101108
int max_m = 0;
102109
int max_n = 0;

source/module_hamilt_lcao/module_gint/gint_rho_gpu.cu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "gint_tools.h"
55
#include "kernels/cuda/gint_rho.cuh"
66

7+
#ifdef _OPENMP
78
#include <omp.h>
9+
#endif
810

911
namespace GintKernel
1012
{
@@ -68,7 +70,9 @@ void gint_rho_gpu(const hamilt::HContainer<double>* dm,
6870
cudaMemcpyHostToDevice));
6971

7072
// calculate the rho for every nbzp bigcells
73+
#ifdef _OPENMP
7174
#pragma omp parallel for num_threads(num_streams) collapse(2)
75+
#endif
7276
for (int i = 0; i < gridt.nbx; i++)
7377
{
7478
for (int j = 0; j < gridt.nby; j++)
@@ -78,7 +82,11 @@ void gint_rho_gpu(const hamilt::HContainer<double>* dm,
7882

7983
checkCuda(cudaSetDevice(gridt.dev_id));
8084
// get stream id
85+
#ifdef _OPENMP
8186
const int sid = omp_get_thread_num();
87+
#else
88+
const int sid = 0;
89+
#endif
8290

8391
int max_m = 0;
8492
int max_n = 0;

source/module_hamilt_lcao/module_gint/gint_vl_gpu.cu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#ifdef _OPENMP
12
#include <omp.h>
3+
#endif
24

35
#include "kernels/cuda/cuda_tools.cuh"
46
#include "module_base/ylm.h"
@@ -71,15 +73,21 @@ void gint_vl_gpu(hamilt::HContainer<double>* hRGint,
7173
Cuda_Mem_Wrapper<double*> gemm_B(max_atompair_per_z, num_streams, true);
7274
Cuda_Mem_Wrapper<double*> gemm_C(max_atompair_per_z, num_streams, true);
7375

76+
#ifdef _OPENMP
7477
#pragma omp parallel for num_threads(num_streams) collapse(2)
78+
#endif
7579
for (int i = 0; i < gridt.nbx; i++)
7680
{
7781
for (int j = 0; j < gridt.nby; j++)
7882
{
7983
// 20240620 Note that it must be set again here because
8084
// cuda's device is not safe in a multi-threaded environment.
8185
checkCuda(cudaSetDevice(gridt.dev_id));
86+
#ifdef _OPENMP
8287
const int sid = omp_get_thread_num();
88+
#else
89+
const int sid = 0;
90+
#endif
8391

8492
int max_m = 0;
8593
int max_n = 0;

0 commit comments

Comments
 (0)