diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 74e1633f..736dc1a3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -40,7 +40,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} queries: +security-and-quality @@ -53,4 +53,4 @@ jobs: make - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/regression.yml b/.github/workflows/regression.yml index 065f0adf..7633c091 100644 --- a/.github/workflows/regression.yml +++ b/.github/workflows/regression.yml @@ -101,6 +101,8 @@ jobs: uses: actions/checkout@v4 - name: Set up MPI uses: mpi4py/setup-mpi@v1 + with: + mpi: openmpi - run: mpicc --version - run: cp config/github-mpicc.mk config.mk - run: make -j 2 @@ -118,6 +120,8 @@ jobs: uses: actions/checkout@v4 - name: Set up MPI uses: mpi4py/setup-mpi@v1 + with: + mpi: openmpi - run: mpicc --version - run: cp config/github-mpicc.mk config.mk - run: sed -i "s/D2Q9/D3Q15/" config.mk diff --git a/codecov.yml b/codecov.yml index 4a9a90fe..bfdc9877 100644 --- a/codecov.yml +++ b/codecov.yml @@ -2,8 +2,7 @@ coverage: status: project: default: - target: 33% - threshold: 2% + informational: true patch: default: informational: true diff --git a/src/colloids.c b/src/colloids.c index cc72f501..ae1b3abc 100644 --- a/src/colloids.c +++ b/src/colloids.c @@ -109,8 +109,8 @@ __host__ void colloids_info_free(colloids_info_t * info) { colloids_info_cell_list_clean(info); free(info->clist); - if (info->map_old) free(info->map_old); - if (info->map_new) free(info->map_new); + free(info->map_old); + free(info->map_new); if (info->target != info) tdpAssert(tdpFree(info->target)); @@ -191,11 +191,16 @@ __host__ int colloids_memcpy(colloids_info_t * info, int flag) { assert((info->target == info)); } else { - colloid_t * tmp; - tdpAssert(tdpMemcpy(&tmp, &info->target->map_new, sizeof(colloid_t **), - tdpMemcpyDeviceToHost)); - tdpAssert(tdpMemcpy(tmp, info->map_new, info->nsites*sizeof(colloid_t *), - tdpMemcpyHostToDevice)); + if (flag == tdpMemcpyHostToDevice) { + colloid_t * tmp; + tdpAssert(tdpMemcpy(&tmp, &info->target->map_new, sizeof(colloid_t **), + tdpMemcpyDeviceToHost)); + tdpAssert(tdpMemcpy(tmp, info->map_new, info->nsites*sizeof(colloid_t *), + tdpMemcpyHostToDevice)); + } + else { + pe_exit(info->pe, "Bad flag in colloids_memcpy()\n"); + } } return 0; diff --git a/src/fe_electro.c b/src/fe_electro.c index 58ce03b2..13b20493 100644 --- a/src/fe_electro.c +++ b/src/fe_electro.c @@ -66,8 +66,9 @@ static fe_vt_t fe_electro_hvt = { (fe_hvector_ft) NULL, (fe_htensor_ft) NULL, (fe_htensor_v_ft) NULL, - (fe_htensor_v_ft) NULL, - (fe_htensor_v_ft) NULL + (fe_stress_v_ft) NULL, + (fe_stress_v_ft) NULL, + (fe_stress_v_ft) NULL }; static __constant__ fe_vt_t fe_electro_dvt = { @@ -158,7 +159,7 @@ __host__ int fe_electro_free(fe_electro_t * fe) { tdpAssert( tdpGetDeviceCount(&ndevice) ); if (ndevice > 0) tdpAssert(tdpFree(fe->target)); - if (fe->mu_ref) free(fe->mu_ref); + free(fe->mu_ref); free(fe); return 0; diff --git a/src/field.c b/src/field.c index ad16de02..4764d2b0 100644 --- a/src/field.c +++ b/src/field.c @@ -168,7 +168,7 @@ __host__ int field_free(field_t * obj) { tdpAssert( tdpFree(obj->target) ); } - if (obj->data) free(obj->data); + free(obj->data); field_halo_free(&obj->h); @@ -1672,7 +1672,7 @@ int field_io_write(field_t * field, int timestep, io_event_t * event) { } io->impl->free(&io); - io_event_report(event, meta, field->name); + io_event_report_write(event, meta, field->name); } return ifail; @@ -1697,9 +1697,16 @@ int field_io_read(field_t * field, int timestep, io_event_t * event) { assert(ifail == 0); if (ifail == 0) { + io_event_record(event, IO_EVENT_READ); io->impl->read(io, filename); + io_event_record(event, IO_EVENT_DISAGGR); field_io_aggr_unpack(field, io->aggr); io->impl->free(&io); + + if (meta->options.report) { + pe_info(field->pe, "MPIIO read from %s\n", filename); + io_event_report_read(event, meta, field->name); + } } return ifail; @@ -1707,7 +1714,7 @@ int field_io_read(field_t * field, int timestep, io_event_t * event) { /***************************************************************************** * - * field_graph_halo_send_create + * field_graph_halo_send_create * *****************************************************************************/ diff --git a/src/field_grad.c b/src/field_grad.c index 456f70a2..e5b660d7 100644 --- a/src/field_grad.c +++ b/src/field_grad.c @@ -298,11 +298,11 @@ __host__ void field_grad_free(field_grad_t * obj) { tdpAssert( tdpFree(obj->target) ); } - if (obj->grad) free(obj->grad); - if (obj->delsq) free(obj->delsq); - if (obj->grad_delsq) free(obj->grad_delsq); - if (obj->delsq_delsq) free(obj->delsq_delsq); - if (obj->d_ab) free(obj->d_ab); + free(obj->grad); + free(obj->delsq); + free(obj->grad_delsq); + free(obj->delsq_delsq); + free(obj->d_ab); obj->field = NULL; free(obj); diff --git a/src/io_aggregator.c b/src/io_aggregator.c index ab3c1ea9..74464ec2 100644 --- a/src/io_aggregator.c +++ b/src/io_aggregator.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2022 The University of Edinburgh + * (c) 2022-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -43,7 +43,7 @@ int io_aggregator_create(io_element_t el, cs_limits_t lim, return 0; err: - if (newaggr) free(newaggr); + free(newaggr); return -1; } diff --git a/src/io_event.c b/src/io_event.c index 77d156ea..f6b9130d 100644 --- a/src/io_event.c +++ b/src/io_event.c @@ -47,12 +47,45 @@ int io_event_record(io_event_t * event, io_event_record_t iorec) { *****************************************************************************/ int io_event_report(io_event_t * event, const io_metadata_t * metadata, - const char * name) { + const char * name, io_event_record_t iorec) { assert(event); assert(metadata); assert(name); + switch (iorec) { + case IO_EVENT_READ: + io_event_report_read(event, metadata, name); + break; + case IO_EVENT_WRITE: + io_event_report_write(event, metadata, name); + break; + default: + /* Internal error. */ + pe_exit(metadata->cs->pe, "Bad io event in report\n"); + } + + return 0; +} + +/***************************************************************************** + * + * io_event_report_read + * + * Report for an i/o event in parallel. + * The aggregation report might want the local data size (currently total). + * The file write is the total data size of the file. + * + * Some refinement might be wanted for multiple files. + * + *****************************************************************************/ + +int io_event_report_read(io_event_t * event, const io_metadata_t * metadata, + const char * name) { + + assert(event); + assert(metadata); + assert(name); /* End of event (for reporting purposes) */ event->time[IO_EVENT_REPORT] = MPI_Wtime(); @@ -64,10 +97,79 @@ int io_event_report(io_event_t * event, const io_metadata_t * metadata, const char * units = NULL; double dunit6 = 1.0e+06; /* Units of data size are MB */ double dunit9 = 1.0e+09; /* Units of data size are GB */ + /* Times (we assume these have been collected correctly! */ + /* Read, then disaggregate, then report */ + + double tr = event->time[IO_EVENT_DISAGGR] - event->time[IO_EVENT_READ]; + double ta = event->time[IO_EVENT_REPORT] - event->time[IO_EVENT_DISAGGR]; + + /* Record size and total file size. */ + + double dr = metadata->element.datasize*metadata->element.count; + double ds = metadata->subfile.sizes[X]*metadata->subfile.sizes[Y]* + metadata->subfile.sizes[Z]; + double db = dr*ds; + + if (db > dunit9) { + /* Use GB */ + units = "GB"; + db = db/dunit9; + } + else { + /* Use MB */ + units = "MB"; + db = db/dunit6; + } + pe_info(pe, "- %10s read %7.3f %2s in %7.3f seconds\n", + name, db, units, tr); + pe_info(pe, "- %10s disaggregated %7.3f %2s in %7.3f seconds\n", + name, db, units, ta); + pe_info(pe, "- %10s rate %7.3f GB per second\n", + name, dr*ds/dunit9/tr); + } + + return 0; +} + +/***************************************************************************** + * + * io_event_report_write + * + * The aggregation report might want the local data size (currently total). + * The file write is the total data size of the file. + * + * Some refinement might be wanted for multiple files. + * + *****************************************************************************/ + +int io_event_report_write(io_event_t * event, const io_metadata_t * metadata, + const char * name) { + + assert(event); + assert(metadata); + assert(name); + + + /* End of event (for reporting purposes) */ + event->time[IO_EVENT_REPORT] = MPI_Wtime(); + + if (metadata->options.report) { + + pe_t * pe = metadata->cs->pe; + + const char * units = NULL; + double dunit6 = 1.0e+06; /* Units of data size are MB */ + double dunit9 = 1.0e+09; /* Units of data size are GB */ + + /* Times (we assume these have been collected correctly! */ + /* Write: aggr is first, write is second, report last */ + double ta = event->time[IO_EVENT_WRITE] - event->time[IO_EVENT_AGGR]; double tw = event->time[IO_EVENT_REPORT] - event->time[IO_EVENT_WRITE]; + /* Record size and total file size. */ + double dr = metadata->element.datasize*metadata->element.count; double ds = metadata->subfile.sizes[X]*metadata->subfile.sizes[Y]* metadata->subfile.sizes[Z]; diff --git a/src/io_event.h b/src/io_event.h index b4abe949..289bdc7f 100644 --- a/src/io_event.h +++ b/src/io_event.h @@ -9,7 +9,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2022 The University of Edinburgh + * (c) 2022-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -22,6 +22,8 @@ enum io_event_record_enum { IO_EVENT_AGGR = 0, + IO_EVENT_DISAGGR, + IO_EVENT_READ, IO_EVENT_WRITE, IO_EVENT_REPORT, IO_EVENT_MAX @@ -38,6 +40,10 @@ struct io_event_s { int io_event_record(io_event_t * event, io_event_record_t iorec); int io_event_report(io_event_t * event, const io_metadata_t * metadata, - const char * name); + const char * name, io_event_record_t iorec); +int io_event_report_read(io_event_t * event, const io_metadata_t * metadata, + const char * name); +int io_event_report_write(io_event_t * event, const io_metadata_t * metadata, + const char * name); #endif diff --git a/src/io_impl_mpio.c b/src/io_impl_mpio.c index 0303e9a5..62c21743 100644 --- a/src/io_impl_mpio.c +++ b/src/io_impl_mpio.c @@ -57,7 +57,7 @@ int io_impl_mpio_create(const io_metadata_t * metadata, return 0; err: - if (mpio) free(mpio); + free(mpio); return -1; } diff --git a/src/io_metadata.c b/src/io_metadata.c index 3e186930..4d390d68 100644 --- a/src/io_metadata.c +++ b/src/io_metadata.c @@ -58,7 +58,7 @@ int io_metadata_create(cs_t * cs, err: - if (meta) free(meta); + free(meta); return -1; } diff --git a/src/lb_data.c b/src/lb_data.c index c7ba18f8..612aafad 100644 --- a/src/lb_data.c +++ b/src/lb_data.c @@ -1417,7 +1417,7 @@ int lb_io_write(lb_t * lb, int timestep, io_event_t * event) { } io->impl->free(&io); - io_event_report(event, meta, "dist"); + io_event_report_write(event, meta, "dist"); } } diff --git a/src/lb_model.c b/src/lb_model.c index 7c1301e7..78db39af 100644 --- a/src/lb_model.c +++ b/src/lb_model.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2021-2022 The University of Edinburgh + * (c) 2021-2024 The University of Edinburgh * * Contributing authors: * Kevin Stratford (kevin@epcc.ed.ac.uk) @@ -108,9 +108,9 @@ int lb_model_free(lb_model_t * model) { free(model->ma); } - if (model->na) free(model->na); - if (model->cv) free(model->cv); - if (model->wv) free(model->wv); + free(model->na); + free(model->cv); + free(model->wv); *model = (lb_model_t) {0}; diff --git a/src/map.c b/src/map.c index ff30a96a..5488c33c 100644 --- a/src/map.c +++ b/src/map.c @@ -58,7 +58,7 @@ int map_create(pe_t * pe, cs_t * cs, const map_options_t * options, err: - if (obj) free(obj); + free(obj); return -1; } @@ -215,8 +215,8 @@ int map_initialise(pe_t * pe, cs_t * cs, const map_options_t * options, /* All failures are before any device memory is involved ... */ if (map->input.cs) io_metadata_finalise(&map->input); if (map->output.cs) io_metadata_finalise(&map->output); - if (map->data) free(map->data); - if (map->status) free(map->status); + free(map->data); + free(map->status); *map = (map_t) {0}; @@ -257,8 +257,8 @@ int map_finalise(map_t * map) { io_metadata_finalise(&map->input); io_metadata_finalise(&map->output); - if (map->data) free(map->data); - if (map->status) free(map->status); + free(map->data); + free(map->status); *map = (map_t) {0}; diff --git a/src/noise.c b/src/noise.c index 1bb58df1..5a7eff6e 100644 --- a/src/noise.c +++ b/src/noise.c @@ -67,7 +67,7 @@ int noise_create(pe_t * pe, cs_t * cs, const noise_options_t * options, return 0; err: - if (obj) free(obj); + free(obj); return -1; } @@ -259,7 +259,7 @@ int noise_finalise(noise_t * ns) { if (ns->output.cs) io_metadata_finalise(&ns->output); if (ns->input.cs) io_metadata_finalise(&ns->input); - if (ns->state) free(ns->state); + free(ns->state); *ns = (noise_t) {}; @@ -648,7 +648,7 @@ int noise_io_write(noise_t * ns, int timestep, io_event_t * event) { if (meta->options.report) { pe_info(ns->pe, "Wrote noise state to file: %s\n", filename); } - io_event_report(event, meta, ns->options.filestub); + io_event_report_write(event, meta, ns->options.filestub); } } diff --git a/src/phi_force_stress.c b/src/phi_force_stress.c index b67ce790..ca6941f2 100644 --- a/src/phi_force_stress.c +++ b/src/phi_force_stress.c @@ -112,7 +112,7 @@ __host__ int pth_free(pth_t * pth) { tdpAssert( tdpFree(pth->target) ); } - if (pth->str) free(pth->str); + free(pth->str); free(pth); return 0; diff --git a/src/psi.c b/src/psi.c index 887a1a2b..11e303db 100644 --- a/src/psi.c +++ b/src/psi.c @@ -9,7 +9,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2012-2023 The University of Edinburgh + * (c) 2012-2024 The University of Edinburgh * * Contributing authors: * Kevin Stratford (kevin@epcc.ed.ac.uk) @@ -42,13 +42,13 @@ int psi_create(pe_t * pe, cs_t * cs, const psi_options_t * opts, ifail = psi_initialise(pe, cs, opts, psi); if (ifail != 0) goto err; - + *pobj = psi; return 0; err: - if (psi) free(psi); + free(psi); return -1; } @@ -169,7 +169,7 @@ int psi_halo_psi(psi_t * psi) { assert(psi); - /* Fudge device implmentation at the moment */ + /* Fudge device implementation at the moment */ field_memcpy(psi->psi, tdpMemcpyHostToDevice); field_halo(psi->psi); field_memcpy(psi->psi, tdpMemcpyDeviceToHost); @@ -588,7 +588,7 @@ int psi_zero_mean(psi_t * psi) { cs_ltot(psi->cs, ltot); cs_nhalo(psi->cs, &nhalo); - cs_nlocal(psi->cs, nlocal); + cs_nlocal(psi->cs, nlocal); cs_cart_comm(psi->cs, &comm); sum_local = 0.0; @@ -681,7 +681,7 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site ic = 1 */ index1 = cs_index(psi->cs, 1, jc, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } @@ -705,11 +705,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end ... */ index1 = cs_index(psi->cs, nlocal[X], jc, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } if (mpicoords[Y] == 0) { @@ -728,11 +728,11 @@ int psi_halo_psijump(psi_t * psi) { /* Not periodic ... just borrow from fluid site jc = 1 */ index1 = cs_index(psi->cs, ic, 1, kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -752,11 +752,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end */ index1 = cs_index(psi->cs, ic, nlocal[Y], kc); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -776,11 +776,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site kc = 1 */ index1 = cs_index(psi->cs, ic, jc, 1); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -800,11 +800,11 @@ int psi_halo_psijump(psi_t * psi) { /* Borrow fluid site at end ... */ index1 = cs_index(psi->cs, ic, jc, nlocal[Z]); psidata[addr_rank0(psi->nsites, index)] = - psidata[addr_rank0(psi->nsites, index1)]; + psidata[addr_rank0(psi->nsites, index1)]; } } } - } + } } @@ -862,8 +862,8 @@ int psi_output_step(psi_t * psi, int its) { * To ensure overall electroneutrality, we consider the following: * * (1) assume surface charges have been assigned - * (2) assume the fluid is initialised with the backgound charge density - * of the electrolyte + * (2) assume the fluid is initialised with the background charge density + * of the electrolyte * (3) assume some number of colloids has been initialised, each * with a given charge. * diff --git a/src/stencil_d3q19.c b/src/stencil_d3q19.c index 49bcb38d..adc0b50b 100644 --- a/src/stencil_d3q19.c +++ b/src/stencil_d3q19.c @@ -6,7 +6,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -69,9 +69,10 @@ int stencil_d3q19_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/stencil_d3q27.c b/src/stencil_d3q27.c index 6a0eb755..3b7c4323 100644 --- a/src/stencil_d3q27.c +++ b/src/stencil_d3q27.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -74,9 +74,10 @@ int stencil_d3q27_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/stencil_d3q7.c b/src/stencil_d3q7.c index 9497fa1f..744c51be 100644 --- a/src/stencil_d3q7.c +++ b/src/stencil_d3q7.c @@ -8,7 +8,7 @@ * Edinburgh Soft Matter and Statistical Physics Group and * Edinburgh Parallel Computing Centre * - * (c) 2023 The University of Edinburgh + * (c) 2023-2024 The University of Edinburgh * * Kevin Stratford (kevin@epcc.ed.ac.uk) * @@ -77,9 +77,10 @@ int stencil_d3q7_create(stencil_t ** stencil) { err: - if (s->wgradients) free(s->wgradients); - if (s->wlaplacian) free(s->wlaplacian); - if (s->cv) free(s->cv); + free(s->wgradients); + free(s->wlaplacian); + free(s->cv); + free(s); *stencil = NULL; diff --git a/src/wall.c b/src/wall.c index 70b945d5..12ce8fe3 100644 --- a/src/wall.c +++ b/src/wall.c @@ -155,14 +155,15 @@ __host__ int wall_free(wall_t * wall) { free(wall->param); /* slip quantities */ - if (wall->linkk) free(wall->linkk); - if (wall->linkq) free(wall->linkq); - if (wall->links) free(wall->links); - - if (wall->linki) free(wall->linki); - if (wall->linkj) free(wall->linkj); - if (wall->linkp) free(wall->linkp); - if (wall->linku) free(wall->linku); + + free(wall->linkk); + free(wall->linkq); + free(wall->links); + + free(wall->linki); + free(wall->linkj); + free(wall->linkp); + free(wall->linku); free(wall);