Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use smart pointers to manage memory and prevent memory leaks #456

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions applications/solvers/dfLowMachFoam/YEqn.H
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ if(flag_mpi_init) MPI_Barrier(PstreamGlobals::MPI_COMM_FOAM);
#ifdef ODE_GPU_SOLVER
scalar dt = runTime.deltaTValue();

memcpy(h_T, &T[0], num_cells * sizeof(double));
memcpy(h_p, &p[0], num_cells * sizeof(double));

forAll(Y, speciesI) {
volScalarField& Yi = Y[speciesI];
memcpy(h_y + speciesI * num_cells, &Yi[0], num_cells * sizeof(double));
Expand All @@ -301,7 +298,7 @@ if(flag_mpi_init) MPI_Barrier(PstreamGlobals::MPI_COMM_FOAM);
}
}

opencc_ode_all(h_T, h_p, h_y_t, 1e-10, dt, CPU);
opencc_ode_all(&T[0], &p[0], h_y_t, 1e-10, dt, CPU);

for (int i = 0; i < num_cells; i++) {
for (int j = 0; j < sp_num; j++) {
Expand Down
14 changes: 3 additions & 11 deletions applications/solvers/dfLowMachFoam/createFields_GPU.H
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,20 @@ forAll(RRGPU, fieldi)
int num_cells = T.size();
int num_species = Y.size();

double* h_T = new double[num_cells];
double* h_p = new double[num_cells];
double* h_y = new double[num_cells * num_species];
double* h_y_t = new double[num_cells * num_species];
int* h_size = new int[1];

memcpy(h_T, &T[0], num_cells * sizeof(double));
memcpy(h_p, &p[0], num_cells * sizeof(double));
std::unique_ptr<double[]> unique_y(new double[num_cells * num_species]); double* h_y = unique_y.get();
std::unique_ptr<double[]> unique_y_t(new double[num_cells * num_species]); double* h_y_t = unique_y_t.get();

forAll(Y, speciesI) {
volScalarField& Yi = Y[speciesI];
memcpy(h_y + speciesI * num_cells, &Yi[0], num_cells * sizeof(double));
}

h_size[0] = num_cells;

int sp_num = num_species;

string mechanismFile = CanteraTorchProperties.lookupOrDefault("CanteraMechanismFile", string(""));
char target_mechanismFile[100];
std::strcpy(target_mechanismFile, mechanismFile.c_str());

opencc_ode_init(target_mechanismFile, num_cells, h_T, h_p, h_y);
opencc_ode_init(target_mechanismFile, num_cells, &T[0], &p[0], h_y);

double* Ynew = new double[num_cells * num_species];
Loading