Skip to content

Update CMake build - #97

Draft
Sichao25 wants to merge 9 commits into
PrincetonUniversity:masterfrom
Sichao25:yus/cmake
Draft

Update CMake build#97
Sichao25 wants to merge 9 commits into
PrincetonUniversity:masterfrom
Sichao25:yus/cmake

Conversation

@Sichao25

@Sichao25 Sichao25 commented Jul 21, 2026

Copy link
Copy Markdown

This PR updates the CMake build for M3DC1. Most of the work was done by @jacobmerson , with a few additional details added by me. I've only run the kprad_2d test so far — not every executable has been tested yet, but this should serve as a good starting point.

TODO:

  • Create build instructions.
  • Test in stellar
  • build with complex option (m3dc1_complex)
  • build with pspline dependency
  • log the known issues

Comment thread unstructured/rmp.f90 Outdated
use math
use field
use mesh_mod
use scorec_mesh_mod

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.

mesh_mod is supposed to be switchable on the build setup through a fortran interface.

@Sichao25

Sichao25 commented Aug 13, 2026

Copy link
Copy Markdown
Author

I encountered the following issues, which required some source code changes to get the build to pass. They're not included in the PR because they don't appear in all configs/environments.

  1. Source code needs updating with complex enabled

The value 1. in the following code needs to be specified as real or complex when complex build is enabled:
https://github.com/PrincetonUniversity/M3DC1/blob/master/unstructured/metricterms_new.f90#L11837

unstructured/metricterms_new.f90
@@ -11834,7 +11834,7 @@ real function volume_pd(mask)
                (tet79(:, OP_DR)**2 + tet79(:, OP_DZ)**2   &
                +tet79(:, OP_DP)**2 * ri2_79)
     ! Heaviside function
     temp79c = sign(1., temp79b) * 0.5 + 0.5
     temp = int1(temp79c*temp79a)
   end if
 #endif

https://github.com/PrincetonUniversity/M3DC1/blob/master/unstructured/basic_mesh.f90#L369

unstructured/basic_mesh.f90
@@ -368,8 +368,13 @@ contains
              if(global_elm(i)%inode(j).gt.max_node) cycle
              do k=1, nodes_per_element
                 if(j.eq.k) cycle
                 call MatSetValue(connectivity, global_elm(i)%inode(j)-1, &
                      global_elm(i)%inode(k)-1, 1., INSERT_VALUES, ierr)
              end do
           end do
        end do
  1. Missing executables in CMake

Some executables are missing, even in the original CMake setup. I'm not sure whether this means we no longer use those executables, or whether they're simply not being built due to some error. Related code are:
https://github.com/PrincetonUniversity/M3DC1/blob/master/unstructured/CMakeLists.txt#L473-L484

#find_package(PSPLINE)
#add_executable(readgato polar.f90 readgato.f90)
#target_link_libraries(readgato ${PSPLINE_LIBRARIES})
#add_executable(read_jsolver polar.f90 read_jsolver_exec.f90)
#target_link_libraries(read_jsolver ${PSPLINE_LIBRARIES})
#add_executable(a2cc readaeqdsk.f90 a2cc.f90)
#target_link_libraries(a2cc )
#target_compile_definitions(a2cc PUBLIC ${DEFS})
#add_executable(kprad kprad.f90 kprad_test.f90)
  1. Building with PSPLINE enabled produces the following error, which may point to a version mismatch in PSPLINE. I am using the latest version at this moment:
undefined reference to `r8mkspline_'
/bin/ld: /M3DC1/unstructured/read_jsolver.f90:174:(.text+0x60a0): undefined reference to `r8evspline_'
/bin/ld: /M3DC1/unstructured/read_jsolver.f90:208:(.text+0x64f5): undefined reference to `r8mkspline_'
/bin/ld: /M3DC1/unstructured/read_jsolver.f90:214:(.text+0x6623): undefined reference to `r8evspline_'
collect2: error: ld returned 1 exit status
  1. The following files run into the error where the same pointer TYPE(C_PTR) :: baseptr needs to satisfy both the MPI and C type APIs, in:
CALL MPI_Win_allocate_shared(arraysize, disp_unit, MPI_INFO_NULL, hostcomm, baseptr, win_mesh_nodes, ierr)

and

CALL C_F_POINTER(baseptr, mesh_nodes, [nodes_per_element, nelms_global])

This only occurs in certain environments (SCOREC and Perlmutter default). A pure Spack environment with gcc@14.2.0 and mpich@4.3.0 does not have this problem.

Affected files:

  • unstructured/particle.f90
  • unstructured/runaway_advection.f90
  1. The PETSc and Trilinos backends seem to be two alternative backends for m3dc1_scorec. However, some source files, such as m3dc1_matrix.cc, are wrapped in #ifdef M3DC1_PETSC. When Trilinos is enabled instead of PETSc, this causes some issues. At the moment, the CMake update here does not include Trilinos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants