Skip to content

Do not store std::string in PETSc-allocated structs#61

Merged
pelesh merged 2 commits into
developfrom
nicholson/fix-strings-structs
May 28, 2026
Merged

Do not store std::string in PETSc-allocated structs#61
pelesh merged 2 commits into
developfrom
nicholson/fix-strings-structs

Conversation

@nkoukpaizan

Copy link
Copy Markdown
Collaborator

Merge request type

  • New feature
  • Resolves bug
  • Documentation
  • Other

Relates to

  • OPFLOW
  • SOPFLOW
  • SCOPFLOW
  • TCOPFLOW
  • CMake build system
  • Spack configuration
  • Manual
  • Web docs
  • Other

This MR updates

  • Header files
  • Source code
  • CMake build system
  • Spack configuration
  • Web docs
  • Manual
  • Other

Summary

This changes the storage of strings in structs that are allocated with PetscCalloc from std::string to char[32]. This essentially reverts a prior attempt to "modernize" the storage of strings, which comes with a few concerns. The application-level strings remain std::string, and they are converted to char[] for storage in the structs.

After Frontier's recent OS upgrade, several tests were failing due to an obscure segmentation fault.

62/62 Testing: SOPFLOW_SOLUTION_OUTPUT_MINIMAL
62/62 Test: SOPFLOW_SOLUTION_OUTPUT_MINIMAL
Command: "/usr/bin/srun" "/lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/build/applications/sopflow" "-netfile" "/lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/datafiles/case9/case9mod.m" "-ctgcfile" "/lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/datafiles/case9/case9.cont" "-scenfile" "/lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/datafiles/case9/10_scenarios_9bus.csv" "-sopflow_solver" "IPOPT" "-sopflow_Ns" "8" "-sopflow_Nc" "3" "-sopflow_enable_multicontingency" "1" "-sopflow_flatten_contingencies" "0" "-save_output" "1" "-opflow_output_format" "MINIMAL" "-sopflow_output_directory" "sopflowout_MINIMAL"
Directory: /lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/build/tests/functionality/sopflow
"SOPFLOW_SOLUTION_OUTPUT_MINIMAL" start time: May 28 15:00 EDT
Output:
----------------------------------------------------------
[ExaGO] SOPFLOW: Application created
[ExaGO] SOPFLOW running with %d scenarios

[ExaGO] SOPFLOW: Using IPOPT solver

[ExaGO] SCOPFLOW: Application created
[ExaGO] SCOPFLOW running with 4 subproblems (base case + 3 contingencies)
[ExaGO] SCOPFLOW: Using IPOPT solver
[0]PETSC ERROR: ------------------------------------------------------------------------
[0]PETSC ERROR: Caught signal number 11 SEGV: Segmentation Violation, probably memory access out of range
[0]PETSC ERROR: Try option -start_in_debugger or -on_error_attach_debugger
[0]PETSC ERROR: or see https://petsc.org/release/faq/#valgrind and https://petsc.org/release/faq/
[0]PETSC ERROR: ---------------------  Stack Frames ------------------------------------
The line numbers in the error traceback are not always exact.
[0] #1 SCOPFLOWSetUp() at /lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/src/scopflow/interface/scopflow.cpp:710
[0] #2 SOPFLOWSetUp() at /lustre/orion/scratch/nkouk/stf006/Codes/ExaGO/src/sopflow/interface/sopflow.cpp:1100
MPICH ERROR [Rank 0] [job id 4731080.144] [Thu May 28 15:00:58 2026] [frontier08535] - Abort(59) (rank 0 in comm 0): application called MPI_Abort(MPI_COMM_WORLD, 59) - process 0

The outstanding stack issue I recall seeing with Valgrind was the std::string values stored in the structs, where the appropriate destructors were not being called. The changes in this PR resolve the failing tests and the Valgrind errors.

We can revisit storing std::string in the structs if we also update the object allocation (e.g., with new) and deallocation. The memory would no longer be owned by PETSc.
Relates to this issue.

@nkoukpaizan nkoukpaizan self-assigned this May 28, 2026
@nkoukpaizan nkoukpaizan added the bug Something isn't working label May 28, 2026
@nkoukpaizan nkoukpaizan marked this pull request as ready for review May 28, 2026 20:58

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests on Frontier pass, changes look good!

@pelesh pelesh merged commit 545a8de into develop May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants