From d56d5fc063cc407f928c0ebf845556fd8f2ede1d Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Mon, 15 Jun 2026 16:58:02 -0400 Subject: [PATCH 1/6] Clean up meson files. - tabs -> 2 spaces per style guide - foreach loop for the extension modules - clean up cpp_args - migrate c++ standard specification to project() - global project argument for `-DUSE_MPI` - Removed `-fPIC`. Meson handles this for us. - set default buildtype to 'release' in project() - can be overridden with `meson setup ... -Dbuildtype=debug` - Add `-march=native` global project argument, conditionally. - Since we don't distribute binaries and expect users to compile pyo3 for themselves, I don't see a reason not to include this flag as it can only help performance. At worst, it does nothing. --- meson.build | 10 +- src/meson.build | 658 ++++++++++++++++++++---------------------------- 2 files changed, 283 insertions(+), 385 deletions(-) diff --git a/meson.build b/meson.build index b2bb9c79..428193ff 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,12 @@ -project('PyORBIT', ['cpp'], version: run_command('python', '-m', 'setuptools_scm').stdout().strip()) +project('PyORBIT', + ['cpp'], + version: run_command('python', '-m', 'setuptools_scm').stdout().strip(), + default_options: [ + 'buildtype=release', + 'cpp_std=c++11', + 'warning_level=3', + ], +) subdir('src') subdir('py/orbit') diff --git a/src/meson.build b/src/meson.build index c223553d..c7474e58 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,14 +1,13 @@ - -#project('orbit', ['cpp'], version: '0.0.1') - - # Add Python installation details python = import('python').find_installation('python3', pure: false) # Add C++ compiler details cpp = meson.get_compiler('cpp') -base = meson.current_source_dir() + '/core' +# Add -march=native if the compiler supports it +if cpp.has_argument('-march=native') + add_project_arguments('-march=native', language: 'cpp') +endif dependencies = [] @@ -17,412 +16,303 @@ dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) # Detecting if MPICH or OPENMPI are installed and enabling support if present - mpi_use = get_option('USE_MPI') -# message('MPI_USE is set to', mpi_use) if mpi_use == 'mpich' - message('Requested to use MPICH as the MPI implementation.') - dependencies += dependency('mpich', version: '>= 4.0.0', required: true) - cpp_args = ['-fPIC', '-std=c++11', '-DUSE_MPI=1'] + message('Requested to use MPICH as the MPI implementation.') + dependencies += dependency('mpich', version: '>= 4.0.0', required: true) + add_project_arguments('-DUSE_MPI=1', language: 'cpp') - # Configure dependencies or settings specific to MPICH + # Configure dependencies or settings specific to MPICH elif mpi_use == 'ompi' - message('Requested to use OpenMPI as the MPI implementation.') - dependencies += dependency('ompi', version: '>= 4.0.0', required: true) - cpp_args = ['-fPIC', '-std=c++11', '-DUSE_MPI=1'] + message('Requested to use OpenMPI as the MPI implementation.') + dependencies += dependency('ompi', version: '>= 4.0.0', required: true) + add_project_arguments('-DUSE_MPI=1', language: 'cpp') elif mpi_use == 'none' - message('Requested to not use MPI.') - cpp_args = ['-fPIC', '-std=c++11'] + message('Requested to not use MPI.') else mpich_dependency = dependency('mpich', version: '>= 4.0.0', required: false) openmpi_dependency = dependency('ompi', version: '>= 4.0.0', required: false) if mpich_dependency.found() - cpp_args = ['-fPIC', '-std=c++11', '-DUSE_MPI=1'] - dependencies += mpich_dependency - message('Using MPICH as the MPI implementation.') + add_project_arguments('-DUSE_MPI=1', language: 'cpp') + dependencies += mpich_dependency + message('Using MPICH as the MPI implementation.') elif openmpi_dependency.found() - cpp_args = ['-fPIC', '-std=c++11', '-DUSE_MPI=1'] - dependencies += openmpi_dependency - message('Using OpenMPI as the MPI implementation.') + add_project_arguments('-DUSE_MPI=1', language: 'cpp') + dependencies += openmpi_dependency + message('Using OpenMPI as the MPI implementation.') else - cpp_args = ['-fPIC', '-std=c++11'] - message('MPI will not be used.') + message('MPI will not be used.') endif endif sources = files([ - 'linac/wrap_linacmodule.cc', - 'linac/tracking/linac_tracking.cc', - 'linac/tracking/wrap_linac_tracking.cc', - 'linac/rfgap/wrap_BaseRfGap.cc', - 'linac/rfgap/BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapTTF_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF.cc', - 'linac/rfgap/BaseRfGap.cc', - 'linac/rfgap/RfGapThreePointTTF.cc', - 'linac/rfgap/MatrixRfGap.cc', - 'linac/rfgap/wrap_BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_SuperFishFieldSource.cc', - 'linac/rfgap/RfGapTTF.cc', - 'linac/rfgap/SuperFishFieldSource.cc', - 'linac/rfgap/RfGapTTF_slow.cc', - 'linac/rfgap/RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_RfGapTTF.cc', - 'linac/rfgap/wrap_MatrixRfGap.cc', - 'orbit/OrbitConst.cc', - 'orbit/wrap_bunch.cc', - 'orbit/wrap_syncpart.cc', - 'orbit/Bunch.cc', - 'orbit/SyncPart.cc', - 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', - 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', - 'orbit/BunchDiagnostics/BunchTwissAnalysis.cc', - 'orbit/BunchDiagnostics/BunchTuneAnalysis.cc', - 'orbit/FieldTracker/wrap_fieldtracker.cc', - 'orbit/FieldTracker/FieldTracker.cc', - 'orbit/MaterialInteractions/wrap_foil.cc', - 'orbit/MaterialInteractions/Foil.cc', - 'orbit/MaterialInteractions/Collimator.cc', - 'orbit/MaterialInteractions/numrecipes.cc', - 'orbit/MaterialInteractions/cross_sections.cc', - 'orbit/MaterialInteractions/wrap_collimator.cc', - 'orbit/MaterialInteractions/MaterialInteractions.cc', - 'orbit/RFCavities/Dual_Harmonic_Cav.cc', - 'orbit/RFCavities/Frequency_Cav.cc', - 'orbit/RFCavities/Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Harmonic_Cav.cc', - 'orbit/RFCavities/Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Frequency_Cav.cc', - 'orbit/RFCavities/wrap_rfcavities.cc', - 'orbit/Impedances/wrap_TImpedance.cc', - 'orbit/Impedances/TImpedance.cc', - 'orbit/Impedances/wrap_impedances.cc', - 'orbit/Impedances/LImpedance.cc', - 'orbit/Impedances/wrap_LImpedance.cc', - 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc', - 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', - 'orbit/Errors/errorbase.cc', - 'orbit/Errors/wrap_errorbase.cc', - 'orbit/ParticlesAttributes/ParticleInitialCoordinates.cc', - 'orbit/ParticlesAttributes/ParticleIdNumber.cc', - 'orbit/ParticlesAttributes/ParticleMacroSize.cc', - 'orbit/ParticlesAttributes/ParticleAttributesFactory.cc', - 'orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc', - 'orbit/ParticlesAttributes/pq_coordinates.cc', - 'orbit/ParticlesAttributes/Evolution.cc', - 'orbit/ParticlesAttributes/ParticleAttributes.cc', - 'orbit/ParticlesAttributes/TurnNumberAttributes.cc', - 'orbit/ParticlesAttributes/LostParticleAttributes.cc', - 'orbit/ParticlesAttributes/ParticlePhaseAttributes.cc', - 'orbit/ParticlesAttributes/part_time.cc', - 'orbit/ParticlesAttributes/AtomPopulations.cc', - 'orbit/Apertures/CircleApertureShape.cc', - 'orbit/Apertures/PhaseAperture.cc', - 'orbit/Apertures/Aperture.cc', - 'orbit/Apertures/wrap_aperture.cc', - 'orbit/Apertures/wrap_CompositeApertureShape.cc', - 'orbit/Apertures/RectangularApertureShape.cc', - 'orbit/Apertures/PyBaseApertureShape.cc', - 'orbit/Apertures/ConvexApertureShape.cc', - 'orbit/Apertures/wrap_ConvexApertureShape.cc', - 'orbit/Apertures/wrap_PyBaseApertureShape.cc', - 'orbit/Apertures/EnergyAperture.cc', - 'orbit/Apertures/BaseAperture.cc', - 'orbit/Apertures/EllipseApertureShape.cc', - 'orbit/Apertures/wrap_BaseAperture.cc', - 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', - 'orbit/Apertures/CompositeApertureShape.cc', - 'orbit/Apertures/wrap_EnergyAperture.cc', - 'orbit/Apertures/wrap_TAperture.cc', - 'orbit/Apertures/wrap_PhaseAperture.cc', - 'orbit/Apertures/BaseApertureShape.cc', - 'trackerrk4/wrap_runge_kutta_tracker.cc', - 'trackerrk4/wrap_py_external_effects.cc', - 'trackerrk4/ExternalEffects.cc', - 'trackerrk4/ExtEffectsContainer.cc', - 'trackerrk4/wrap_trackerrk4.cc', - 'trackerrk4/PyExternalEffects.cc', - 'trackerrk4/RungeKuttaTracker.cc', - 'trackerrk4/wrap_ext_effects_container.cc', - 'mpi/wrap_orbit_mpi.cc', - 'mpi/wrap_mpi_comm.cc', - 'mpi/orbit_mpi.cc', - 'mpi/wrap_mpi_datatype.cc', - 'mpi/wrap_mpi_request.cc', - 'mpi/wrap_mpi_op.cc', - 'mpi/wrap_mpi_status.cc', - 'mpi/wrap_mpi_group.cc', - 'spacecharge/PoissonSolverFFT3D.cc', - 'spacecharge/SpaceChargeCalcUnifEllipse.cc', - 'spacecharge/ForceSolver2D.cc', - 'spacecharge/PoissonSolverFFT2D.cc', - 'spacecharge/wrap_poissonsolverfft2d.cc', - 'spacecharge/wrap_poissonsolverfft3d.cc', - 'spacecharge/PoissonSolver2D.cc', - 'spacecharge/SpaceChargeForceCalc2p5D.cc', - 'spacecharge/PoissonSolver3D.cc', - 'spacecharge/SpaceChargeCalc3D.cc', - 'spacecharge/wrap_boundary2d.cc', - 'spacecharge/wrap_forcesolverfft2d.cc', - 'spacecharge/ForceSolverFFT2D.cc', - 'spacecharge/SpaceChargeCalcSliceBySlice2D.cc', - 'spacecharge/Grid3D.cc', - 'spacecharge/wrap_spacecharge.cc', - 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', - 'spacecharge/Grid2D.cc', - 'spacecharge/SpaceChargeCalc2p5Drb.cc', - 'spacecharge/Grid1D.cc', - 'spacecharge/LSpaceChargeCalc.cc', - 'spacecharge/wrap_grid1D.cc', - 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', - 'spacecharge/ShapedBoundary2D.cc', - 'spacecharge/wrap_grid3D.cc', - 'spacecharge/BaseBoundary2D.cc', - 'spacecharge/wrap_grid2D.cc', - 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', - 'spacecharge/wrap_spacechargecalc3d.cc', - 'spacecharge/UniformEllipsoidFieldCalculator.cc', - 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', - 'spacecharge/SpaceChargeCalc2p5D.cc', - 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', - 'spacecharge/wrap_spacechargecalc2p5d.cc', - 'spacecharge/wrap_lspacechargecalc.cc', - 'utils/wrap_function.cc', - 'utils/FieldSourceContainer.cc', - 'utils/AttributesBucket.cc', - 'utils/bessel.cc', - 'utils/PyBaseFieldSource.cc', - 'utils/wrap_field_source_container.cc', - 'utils/OU_SplineCH.cc', - 'utils/CppPyWrapper.cc', - 'utils/wrap_random.cc', - 'utils/wrap_utils.cc', - 'utils/StringUtils.cc', - 'utils/wrap_py_base_field_source.cc', - 'utils/wrap_splinech.cc', - 'utils/Random.cc', - 'utils/wrap_numrecipes.cc', - 'utils/BaseFieldSource.cc', - 'utils/OU_Function.cc', - 'utils/MathPolynomial.cc', - 'utils/BufferStore.cc', - 'utils/statistics/wrap_statmoments2d.cc', - 'utils/statistics/StatMoments2D.cc', - 'utils/field_sources/wrap_loop_field_source.cc', - 'utils/field_sources/LoopFieldSource.cc', - 'utils/field_sources/QuadFieldSource.cc', - 'utils/field_sources/ShiftedFieldSource.cc', - 'utils/field_sources/wrap_dipole_field_source.cc', - 'utils/field_sources/wrap_quad_field_source.cc', - 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', - 'utils/field_sources/DipoleFieldSource.cc', - 'utils/field_sources/wrap_field_sources_module.cc', - 'utils/field_sources/MagnetFieldSourceGrid3D.cc', - 'utils/integration/gauss_legendre_points.cc', - 'utils/integration/wrap_gauss_legendre_integrator.cc', - 'utils/integration/GaussLegendreIntegrator.cc', - 'utils/bunch/ParticlesWithIdFunctions.cc', - 'utils/bunch/wrap_bunch_extrema_calculator.cc', - 'utils/bunch/TwissFilteringFunctions.cc', - 'utils/bunch/InitialCoordsAttrFunctions.cc', - 'utils/bunch/BunchExtremaCalculator.cc', - 'utils/bunch/wrap_bunch_utils_functions.cc', - 'utils/harmonic_analysis/HarmonicData.cc', - 'utils/harmonic_analysis/wrap_harmonic_data.cc', - 'utils/polynomial/wrap_polynomial.cc', - 'utils/polynomial/OU_Polynomial.cc', - 'utils/matrix/wrap_matrix.cc', - 'utils/matrix/PhaseVector.cc', - 'utils/matrix/MatrixOperations.cc', - 'utils/matrix/wrap_phase_vector.cc', - 'utils/matrix/Matrix.cc', - 'teapot/wrap_teapotbase.cc', - 'teapot/wrap_matrix_generator.cc', - 'teapot/teapotbase.cc', - 'teapot/MatrixGenerator.cc' + 'linac/wrap_linacmodule.cc', + 'linac/tracking/linac_tracking.cc', + 'linac/tracking/wrap_linac_tracking.cc', + 'linac/rfgap/wrap_BaseRfGap.cc', + 'linac/rfgap/BaseRfGap_slow.cc', + 'linac/rfgap/wrap_RfGapTTF_slow.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF.cc', + 'linac/rfgap/BaseRfGap.cc', + 'linac/rfgap/RfGapThreePointTTF.cc', + 'linac/rfgap/MatrixRfGap.cc', + 'linac/rfgap/wrap_BaseRfGap_slow.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', + 'linac/rfgap/wrap_SuperFishFieldSource.cc', + 'linac/rfgap/RfGapTTF.cc', + 'linac/rfgap/SuperFishFieldSource.cc', + 'linac/rfgap/RfGapTTF_slow.cc', + 'linac/rfgap/RfGapThreePointTTF_slow.cc', + 'linac/rfgap/wrap_RfGapTTF.cc', + 'linac/rfgap/wrap_MatrixRfGap.cc', + 'orbit/OrbitConst.cc', + 'orbit/wrap_bunch.cc', + 'orbit/wrap_syncpart.cc', + 'orbit/Bunch.cc', + 'orbit/SyncPart.cc', + 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', + 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', + 'orbit/BunchDiagnostics/BunchTwissAnalysis.cc', + 'orbit/BunchDiagnostics/BunchTuneAnalysis.cc', + 'orbit/FieldTracker/wrap_fieldtracker.cc', + 'orbit/FieldTracker/FieldTracker.cc', + 'orbit/MaterialInteractions/wrap_foil.cc', + 'orbit/MaterialInteractions/Foil.cc', + 'orbit/MaterialInteractions/Collimator.cc', + 'orbit/MaterialInteractions/numrecipes.cc', + 'orbit/MaterialInteractions/cross_sections.cc', + 'orbit/MaterialInteractions/wrap_collimator.cc', + 'orbit/MaterialInteractions/MaterialInteractions.cc', + 'orbit/RFCavities/Dual_Harmonic_Cav.cc', + 'orbit/RFCavities/Frequency_Cav.cc', + 'orbit/RFCavities/Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Harmonic_Cav.cc', + 'orbit/RFCavities/Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Frequency_Cav.cc', + 'orbit/RFCavities/wrap_rfcavities.cc', + 'orbit/Impedances/wrap_TImpedance.cc', + 'orbit/Impedances/TImpedance.cc', + 'orbit/Impedances/wrap_impedances.cc', + 'orbit/Impedances/LImpedance.cc', + 'orbit/Impedances/wrap_LImpedance.cc', + 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc', + 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', + 'orbit/Errors/errorbase.cc', + 'orbit/Errors/wrap_errorbase.cc', + 'orbit/ParticlesAttributes/ParticleInitialCoordinates.cc', + 'orbit/ParticlesAttributes/ParticleIdNumber.cc', + 'orbit/ParticlesAttributes/ParticleMacroSize.cc', + 'orbit/ParticlesAttributes/ParticleAttributesFactory.cc', + 'orbit/ParticlesAttributes/WaveFunctionAmplitudes.cc', + 'orbit/ParticlesAttributes/pq_coordinates.cc', + 'orbit/ParticlesAttributes/Evolution.cc', + 'orbit/ParticlesAttributes/ParticleAttributes.cc', + 'orbit/ParticlesAttributes/TurnNumberAttributes.cc', + 'orbit/ParticlesAttributes/LostParticleAttributes.cc', + 'orbit/ParticlesAttributes/ParticlePhaseAttributes.cc', + 'orbit/ParticlesAttributes/part_time.cc', + 'orbit/ParticlesAttributes/AtomPopulations.cc', + 'orbit/Apertures/CircleApertureShape.cc', + 'orbit/Apertures/PhaseAperture.cc', + 'orbit/Apertures/Aperture.cc', + 'orbit/Apertures/wrap_aperture.cc', + 'orbit/Apertures/wrap_CompositeApertureShape.cc', + 'orbit/Apertures/RectangularApertureShape.cc', + 'orbit/Apertures/PyBaseApertureShape.cc', + 'orbit/Apertures/ConvexApertureShape.cc', + 'orbit/Apertures/wrap_ConvexApertureShape.cc', + 'orbit/Apertures/wrap_PyBaseApertureShape.cc', + 'orbit/Apertures/EnergyAperture.cc', + 'orbit/Apertures/BaseAperture.cc', + 'orbit/Apertures/EllipseApertureShape.cc', + 'orbit/Apertures/wrap_BaseAperture.cc', + 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', + 'orbit/Apertures/CompositeApertureShape.cc', + 'orbit/Apertures/wrap_EnergyAperture.cc', + 'orbit/Apertures/wrap_TAperture.cc', + 'orbit/Apertures/wrap_PhaseAperture.cc', + 'orbit/Apertures/BaseApertureShape.cc', + 'trackerrk4/wrap_runge_kutta_tracker.cc', + 'trackerrk4/wrap_py_external_effects.cc', + 'trackerrk4/ExternalEffects.cc', + 'trackerrk4/ExtEffectsContainer.cc', + 'trackerrk4/wrap_trackerrk4.cc', + 'trackerrk4/PyExternalEffects.cc', + 'trackerrk4/RungeKuttaTracker.cc', + 'trackerrk4/wrap_ext_effects_container.cc', + 'mpi/wrap_orbit_mpi.cc', + 'mpi/wrap_mpi_comm.cc', + 'mpi/orbit_mpi.cc', + 'mpi/wrap_mpi_datatype.cc', + 'mpi/wrap_mpi_request.cc', + 'mpi/wrap_mpi_op.cc', + 'mpi/wrap_mpi_status.cc', + 'mpi/wrap_mpi_group.cc', + 'spacecharge/PoissonSolverFFT3D.cc', + 'spacecharge/SpaceChargeCalcUnifEllipse.cc', + 'spacecharge/ForceSolver2D.cc', + 'spacecharge/PoissonSolverFFT2D.cc', + 'spacecharge/wrap_poissonsolverfft2d.cc', + 'spacecharge/wrap_poissonsolverfft3d.cc', + 'spacecharge/PoissonSolver2D.cc', + 'spacecharge/SpaceChargeForceCalc2p5D.cc', + 'spacecharge/PoissonSolver3D.cc', + 'spacecharge/SpaceChargeCalc3D.cc', + 'spacecharge/wrap_boundary2d.cc', + 'spacecharge/wrap_forcesolverfft2d.cc', + 'spacecharge/ForceSolverFFT2D.cc', + 'spacecharge/SpaceChargeCalcSliceBySlice2D.cc', + 'spacecharge/Grid3D.cc', + 'spacecharge/wrap_spacecharge.cc', + 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', + 'spacecharge/Grid2D.cc', + 'spacecharge/SpaceChargeCalc2p5Drb.cc', + 'spacecharge/Grid1D.cc', + 'spacecharge/LSpaceChargeCalc.cc', + 'spacecharge/wrap_grid1D.cc', + 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', + 'spacecharge/ShapedBoundary2D.cc', + 'spacecharge/wrap_grid3D.cc', + 'spacecharge/BaseBoundary2D.cc', + 'spacecharge/wrap_grid2D.cc', + 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', + 'spacecharge/wrap_spacechargecalc3d.cc', + 'spacecharge/UniformEllipsoidFieldCalculator.cc', + 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', + 'spacecharge/SpaceChargeCalc2p5D.cc', + 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', + 'spacecharge/wrap_spacechargecalc2p5d.cc', + 'spacecharge/wrap_lspacechargecalc.cc', + 'utils/wrap_function.cc', + 'utils/FieldSourceContainer.cc', + 'utils/AttributesBucket.cc', + 'utils/bessel.cc', + 'utils/PyBaseFieldSource.cc', + 'utils/wrap_field_source_container.cc', + 'utils/OU_SplineCH.cc', + 'utils/CppPyWrapper.cc', + 'utils/wrap_random.cc', + 'utils/wrap_utils.cc', + 'utils/StringUtils.cc', + 'utils/wrap_py_base_field_source.cc', + 'utils/wrap_splinech.cc', + 'utils/Random.cc', + 'utils/wrap_numrecipes.cc', + 'utils/BaseFieldSource.cc', + 'utils/OU_Function.cc', + 'utils/MathPolynomial.cc', + 'utils/BufferStore.cc', + 'utils/statistics/wrap_statmoments2d.cc', + 'utils/statistics/StatMoments2D.cc', + 'utils/field_sources/wrap_loop_field_source.cc', + 'utils/field_sources/LoopFieldSource.cc', + 'utils/field_sources/QuadFieldSource.cc', + 'utils/field_sources/ShiftedFieldSource.cc', + 'utils/field_sources/wrap_dipole_field_source.cc', + 'utils/field_sources/wrap_quad_field_source.cc', + 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', + 'utils/field_sources/DipoleFieldSource.cc', + 'utils/field_sources/wrap_field_sources_module.cc', + 'utils/field_sources/MagnetFieldSourceGrid3D.cc', + 'utils/integration/gauss_legendre_points.cc', + 'utils/integration/wrap_gauss_legendre_integrator.cc', + 'utils/integration/GaussLegendreIntegrator.cc', + 'utils/bunch/ParticlesWithIdFunctions.cc', + 'utils/bunch/wrap_bunch_extrema_calculator.cc', + 'utils/bunch/TwissFilteringFunctions.cc', + 'utils/bunch/InitialCoordsAttrFunctions.cc', + 'utils/bunch/BunchExtremaCalculator.cc', + 'utils/bunch/wrap_bunch_utils_functions.cc', + 'utils/harmonic_analysis/HarmonicData.cc', + 'utils/harmonic_analysis/wrap_harmonic_data.cc', + 'utils/polynomial/wrap_polynomial.cc', + 'utils/polynomial/OU_Polynomial.cc', + 'utils/matrix/wrap_matrix.cc', + 'utils/matrix/PhaseVector.cc', + 'utils/matrix/MatrixOperations.cc', + 'utils/matrix/wrap_phase_vector.cc', + 'utils/matrix/Matrix.cc', + 'teapot/wrap_teapotbase.cc', + 'teapot/wrap_matrix_generator.cc', + 'teapot/teapotbase.cc', + 'teapot/MatrixGenerator.cc' ]) + inc = include_directories([ - 'main', - 'orbit/SynchPartRedefinition', - 'trackerrk4', - 'utils/ellipticalint', - 'teapot', - 'mpi', - 'orbit/ParticlesAttributes', - 'orbit/Errors', - 'orbit/FieldTracker', - 'utils/statistics', - 'utils', - 'linac/tracking', - 'spacecharge', - 'orbit/MaterialInteractions', - 'utils/field_sources', - 'utils/bunch', - 'orbit/Impedances', - 'utils/harmonic_analysis', - 'linac', - 'utils/polynomial', - 'linac/rfgap', - 'orbit/RFCavities', - 'utils/matrix', - 'orbit/BunchDiagnostics', - 'orbit', - 'utils/integration', - 'orbit/Apertures' + 'main', + 'orbit/SynchPartRedefinition', + 'trackerrk4', + 'utils/ellipticalint', + 'teapot', + 'mpi', + 'orbit/ParticlesAttributes', + 'orbit/Errors', + 'orbit/FieldTracker', + 'utils/statistics', + 'utils', + 'linac/tracking', + 'spacecharge', + 'orbit/MaterialInteractions', + 'utils/field_sources', + 'utils/bunch', + 'orbit/Impedances', + 'utils/harmonic_analysis', + 'linac', + 'utils/polynomial', + 'linac/rfgap', + 'orbit/RFCavities', + 'utils/matrix', + 'orbit/BunchDiagnostics', + 'orbit', + 'utils/integration', + 'orbit/Apertures' ]) - -core_lib = library('core', - sources: sources, - include_directories: inc, - cpp_args: cpp_args, - override_options: ['b_lundef=false'], - dependencies: dependencies, - install: true, +core_lib = library( + 'core', + sources: sources, + include_directories: inc, + override_options: ['b_lundef=false'], + dependencies: dependencies, + install: true, ) core_dep = declare_dependency(link_with : core_lib) -python.extension_module('orbit_mpi', - sources: [base + '/mpi_init.cc'], - include_directories: inc, - cpp_args: cpp_args, - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - +ext_modules = { + 'orbit_mpi': 'mpi_init.cc', + 'bunch': 'bunch_init.cc', + 'spacecharge': 'spacecharge_init.cc', + 'trackerrk4': 'trackerrk4_init.cc', + 'teapot_base': 'teapot_base_init.cc', + 'linac': 'linac_init.cc', + 'orbit_utils': 'utils_init.cc', + 'aperture': 'aperture_init.cc', + 'foil': 'foil_init.cc', + 'field_sources': 'field_sources_init.cc', + 'rfcavities': 'rfcavities_init.cc', + 'impedances': 'impedances_init.cc', + 'fieldtracker': 'fieldtracker_init.cc', + 'collimator': 'collimator_init.cc', + 'error_base': 'error_base_init.cc', +} -python.extension_module('bunch', - sources: [base + '/bunch_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('spacecharge', - sources: [base + '/spacecharge_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('trackerrk4', - sources: [base + '/trackerrk4_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('teapot_base', - sources: [base + '/teapot_base_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('linac', - sources: [base + '/linac_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('orbit_utils', - sources: [base + '/utils_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('aperture', - sources: [base + '/aperture_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('foil', - sources: [base + '/foil_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('field_sources', - sources: [base + '/field_sources_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('rfcavities', - sources: [base + '/rfcavities_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('impedances', - sources: [base + '/impedances_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('fieldtracker', - sources: [base + '/fieldtracker_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) - -python.extension_module('collimator', - sources: [base + '/collimator_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) +base = meson.current_source_dir() + '/core' -python.extension_module('error_base', - sources: [base + '/error_base_init.cc'], - include_directories: inc, - cpp_args: ['-fPIC', '-std=c++11'], - dependencies: [core_dep], - install: true, - subdir: 'orbit/core', -) +foreach name, src : ext_modules + python.extension_module( + name, + sources: base / src, + include_directories: inc, + dependencies: [core_dep], + install: true, + subdir: 'orbit/core', + ) +endforeach From eeadd5ff732036bf5a2a65c61be8313a63353208 Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Tue, 16 Jun 2026 10:30:45 -0400 Subject: [PATCH 2/6] Also enable link time optimization --- meson.build | 1 + 1 file changed, 1 insertion(+) diff --git a/meson.build b/meson.build index 428193ff..d37025ea 100644 --- a/meson.build +++ b/meson.build @@ -3,6 +3,7 @@ project('PyORBIT', version: run_command('python', '-m', 'setuptools_scm').stdout().strip(), default_options: [ 'buildtype=release', + 'b_lto=true', 'cpp_std=c++11', 'warning_level=3', ], From d50e5a0004a03586413864214698dc3619893dda Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Thu, 18 Jun 2026 17:48:43 -0400 Subject: [PATCH 3/6] Produce pkgconfig info for libpyorbit. Overall restructuring so we don't ship more than necessary. --- src/meson.build | 427 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 296 insertions(+), 131 deletions(-) diff --git a/src/meson.build b/src/meson.build index c7474e58..84d484f6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -17,21 +17,20 @@ dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) # Detecting if MPICH or OPENMPI are installed and enabling support if present mpi_use = get_option('USE_MPI') +use_mpi_flag = '0' if mpi_use == 'mpich' message('Requested to use MPICH as the MPI implementation.') dependencies += dependency('mpich', version: '>= 4.0.0', required: true) add_project_arguments('-DUSE_MPI=1', language: 'cpp') - - # Configure dependencies or settings specific to MPICH + use_mpi_flag = '1' elif mpi_use == 'ompi' message('Requested to use OpenMPI as the MPI implementation.') dependencies += dependency('ompi', version: '>= 4.0.0', required: true) add_project_arguments('-DUSE_MPI=1', language: 'cpp') - + use_mpi_flag = '1' elif mpi_use == 'none' message('Requested to not use MPI.') - else mpich_dependency = dependency('mpich', version: '>= 4.0.0', required: false) openmpi_dependency = dependency('ompi', version: '>= 4.0.0', required: false) @@ -40,10 +39,12 @@ else add_project_arguments('-DUSE_MPI=1', language: 'cpp') dependencies += mpich_dependency message('Using MPICH as the MPI implementation.') + use_mpi_flag = '1' elif openmpi_dependency.found() add_project_arguments('-DUSE_MPI=1', language: 'cpp') dependencies += openmpi_dependency message('Using OpenMPI as the MPI implementation.') + use_mpi_flag = '1' else message('MPI will not be used.') endif @@ -51,61 +52,34 @@ else endif sources = files([ - 'linac/wrap_linacmodule.cc', 'linac/tracking/linac_tracking.cc', - 'linac/tracking/wrap_linac_tracking.cc', - 'linac/rfgap/wrap_BaseRfGap.cc', 'linac/rfgap/BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapTTF_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF.cc', 'linac/rfgap/BaseRfGap.cc', 'linac/rfgap/RfGapThreePointTTF.cc', 'linac/rfgap/MatrixRfGap.cc', - 'linac/rfgap/wrap_BaseRfGap_slow.cc', - 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_SuperFishFieldSource.cc', 'linac/rfgap/RfGapTTF.cc', 'linac/rfgap/SuperFishFieldSource.cc', 'linac/rfgap/RfGapTTF_slow.cc', 'linac/rfgap/RfGapThreePointTTF_slow.cc', - 'linac/rfgap/wrap_RfGapTTF.cc', - 'linac/rfgap/wrap_MatrixRfGap.cc', 'orbit/OrbitConst.cc', - 'orbit/wrap_bunch.cc', - 'orbit/wrap_syncpart.cc', 'orbit/Bunch.cc', 'orbit/SyncPart.cc', - 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', - 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', 'orbit/BunchDiagnostics/BunchTwissAnalysis.cc', 'orbit/BunchDiagnostics/BunchTuneAnalysis.cc', - 'orbit/FieldTracker/wrap_fieldtracker.cc', 'orbit/FieldTracker/FieldTracker.cc', - 'orbit/MaterialInteractions/wrap_foil.cc', 'orbit/MaterialInteractions/Foil.cc', 'orbit/MaterialInteractions/Collimator.cc', 'orbit/MaterialInteractions/numrecipes.cc', 'orbit/MaterialInteractions/cross_sections.cc', - 'orbit/MaterialInteractions/wrap_collimator.cc', 'orbit/MaterialInteractions/MaterialInteractions.cc', 'orbit/RFCavities/Dual_Harmonic_Cav.cc', 'orbit/RFCavities/Frequency_Cav.cc', 'orbit/RFCavities/Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Harmonic_Cav.cc', 'orbit/RFCavities/Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', - 'orbit/RFCavities/wrap_Barrier_Cav.cc', - 'orbit/RFCavities/wrap_Frequency_Cav.cc', - 'orbit/RFCavities/wrap_rfcavities.cc', - 'orbit/Impedances/wrap_TImpedance.cc', 'orbit/Impedances/TImpedance.cc', - 'orbit/Impedances/wrap_impedances.cc', 'orbit/Impedances/LImpedance.cc', - 'orbit/Impedances/wrap_LImpedance.cc', 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc', - 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', 'orbit/Errors/errorbase.cc', - 'orbit/Errors/wrap_errorbase.cc', 'orbit/ParticlesAttributes/ParticleInitialCoordinates.cc', 'orbit/ParticlesAttributes/ParticleIdNumber.cc', 'orbit/ParticlesAttributes/ParticleMacroSize.cc', @@ -122,194 +96,385 @@ sources = files([ 'orbit/Apertures/CircleApertureShape.cc', 'orbit/Apertures/PhaseAperture.cc', 'orbit/Apertures/Aperture.cc', - 'orbit/Apertures/wrap_aperture.cc', - 'orbit/Apertures/wrap_CompositeApertureShape.cc', 'orbit/Apertures/RectangularApertureShape.cc', 'orbit/Apertures/PyBaseApertureShape.cc', 'orbit/Apertures/ConvexApertureShape.cc', - 'orbit/Apertures/wrap_ConvexApertureShape.cc', - 'orbit/Apertures/wrap_PyBaseApertureShape.cc', 'orbit/Apertures/EnergyAperture.cc', 'orbit/Apertures/BaseAperture.cc', 'orbit/Apertures/EllipseApertureShape.cc', - 'orbit/Apertures/wrap_BaseAperture.cc', - 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', 'orbit/Apertures/CompositeApertureShape.cc', - 'orbit/Apertures/wrap_EnergyAperture.cc', - 'orbit/Apertures/wrap_TAperture.cc', - 'orbit/Apertures/wrap_PhaseAperture.cc', 'orbit/Apertures/BaseApertureShape.cc', - 'trackerrk4/wrap_runge_kutta_tracker.cc', - 'trackerrk4/wrap_py_external_effects.cc', 'trackerrk4/ExternalEffects.cc', 'trackerrk4/ExtEffectsContainer.cc', - 'trackerrk4/wrap_trackerrk4.cc', 'trackerrk4/PyExternalEffects.cc', 'trackerrk4/RungeKuttaTracker.cc', - 'trackerrk4/wrap_ext_effects_container.cc', - 'mpi/wrap_orbit_mpi.cc', - 'mpi/wrap_mpi_comm.cc', 'mpi/orbit_mpi.cc', - 'mpi/wrap_mpi_datatype.cc', - 'mpi/wrap_mpi_request.cc', - 'mpi/wrap_mpi_op.cc', - 'mpi/wrap_mpi_status.cc', - 'mpi/wrap_mpi_group.cc', 'spacecharge/PoissonSolverFFT3D.cc', 'spacecharge/SpaceChargeCalcUnifEllipse.cc', 'spacecharge/ForceSolver2D.cc', 'spacecharge/PoissonSolverFFT2D.cc', - 'spacecharge/wrap_poissonsolverfft2d.cc', - 'spacecharge/wrap_poissonsolverfft3d.cc', 'spacecharge/PoissonSolver2D.cc', 'spacecharge/SpaceChargeForceCalc2p5D.cc', 'spacecharge/PoissonSolver3D.cc', 'spacecharge/SpaceChargeCalc3D.cc', - 'spacecharge/wrap_boundary2d.cc', - 'spacecharge/wrap_forcesolverfft2d.cc', 'spacecharge/ForceSolverFFT2D.cc', 'spacecharge/SpaceChargeCalcSliceBySlice2D.cc', 'spacecharge/Grid3D.cc', - 'spacecharge/wrap_spacecharge.cc', - 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', - 'spacecharge/Grid2D.cc', 'spacecharge/SpaceChargeCalc2p5Drb.cc', + 'spacecharge/Grid2D.cc', + 'spacecharge/SpaceChargeCalc2p5D.cc', 'spacecharge/Grid1D.cc', 'spacecharge/LSpaceChargeCalc.cc', - 'spacecharge/wrap_grid1D.cc', - 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', 'spacecharge/ShapedBoundary2D.cc', - 'spacecharge/wrap_grid3D.cc', 'spacecharge/BaseBoundary2D.cc', - 'spacecharge/wrap_grid2D.cc', - 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', - 'spacecharge/wrap_spacechargecalc3d.cc', 'spacecharge/UniformEllipsoidFieldCalculator.cc', - 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', - 'spacecharge/SpaceChargeCalc2p5D.cc', - 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', - 'spacecharge/wrap_spacechargecalc2p5d.cc', - 'spacecharge/wrap_lspacechargecalc.cc', - 'utils/wrap_function.cc', 'utils/FieldSourceContainer.cc', 'utils/AttributesBucket.cc', 'utils/bessel.cc', 'utils/PyBaseFieldSource.cc', - 'utils/wrap_field_source_container.cc', 'utils/OU_SplineCH.cc', 'utils/CppPyWrapper.cc', - 'utils/wrap_random.cc', - 'utils/wrap_utils.cc', 'utils/StringUtils.cc', - 'utils/wrap_py_base_field_source.cc', - 'utils/wrap_splinech.cc', 'utils/Random.cc', - 'utils/wrap_numrecipes.cc', 'utils/BaseFieldSource.cc', 'utils/OU_Function.cc', 'utils/MathPolynomial.cc', 'utils/BufferStore.cc', - 'utils/statistics/wrap_statmoments2d.cc', 'utils/statistics/StatMoments2D.cc', - 'utils/field_sources/wrap_loop_field_source.cc', 'utils/field_sources/LoopFieldSource.cc', 'utils/field_sources/QuadFieldSource.cc', 'utils/field_sources/ShiftedFieldSource.cc', - 'utils/field_sources/wrap_dipole_field_source.cc', - 'utils/field_sources/wrap_quad_field_source.cc', - 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', 'utils/field_sources/DipoleFieldSource.cc', - 'utils/field_sources/wrap_field_sources_module.cc', 'utils/field_sources/MagnetFieldSourceGrid3D.cc', 'utils/integration/gauss_legendre_points.cc', - 'utils/integration/wrap_gauss_legendre_integrator.cc', 'utils/integration/GaussLegendreIntegrator.cc', 'utils/bunch/ParticlesWithIdFunctions.cc', - 'utils/bunch/wrap_bunch_extrema_calculator.cc', 'utils/bunch/TwissFilteringFunctions.cc', 'utils/bunch/InitialCoordsAttrFunctions.cc', 'utils/bunch/BunchExtremaCalculator.cc', - 'utils/bunch/wrap_bunch_utils_functions.cc', 'utils/harmonic_analysis/HarmonicData.cc', - 'utils/harmonic_analysis/wrap_harmonic_data.cc', - 'utils/polynomial/wrap_polynomial.cc', 'utils/polynomial/OU_Polynomial.cc', - 'utils/matrix/wrap_matrix.cc', 'utils/matrix/PhaseVector.cc', 'utils/matrix/MatrixOperations.cc', - 'utils/matrix/wrap_phase_vector.cc', 'utils/matrix/Matrix.cc', - 'teapot/wrap_teapotbase.cc', - 'teapot/wrap_matrix_generator.cc', 'teapot/teapotbase.cc', 'teapot/MatrixGenerator.cc' ]) inc = include_directories([ 'main', - 'orbit/SynchPartRedefinition', - 'trackerrk4', - 'utils/ellipticalint', - 'teapot', 'mpi', - 'orbit/ParticlesAttributes', + 'orbit', + 'orbit/Apertures', + 'orbit/BunchDiagnostics', 'orbit/Errors', 'orbit/FieldTracker', - 'utils/statistics', - 'utils', - 'linac/tracking', - 'spacecharge', + 'orbit/Impedances', 'orbit/MaterialInteractions', - 'utils/field_sources', + 'orbit/ParticlesAttributes', + 'orbit/RFCavities', + 'orbit/SynchPartRedefinition', + 'spacecharge', + 'teapot', + 'trackerrk4', + 'utils', 'utils/bunch', - 'orbit/Impedances', + 'utils/ellipticalint', + 'utils/field_sources', 'utils/harmonic_analysis', - 'linac', + 'utils/integration', + 'utils/matrix', 'utils/polynomial', + 'utils/statistics', + 'linac', 'linac/rfgap', - 'orbit/RFCavities', - 'utils/matrix', - 'orbit/BunchDiagnostics', - 'orbit', - 'utils/integration', - 'orbit/Apertures' + 'linac/tracking', ]) core_lib = library( - 'core', + 'pyorbit3_core', sources: sources, include_directories: inc, - override_options: ['b_lundef=false'], dependencies: dependencies, + override_options: ['b_lundef=false'], install: true, ) -core_dep = declare_dependency(link_with : core_lib) +core_dep = declare_dependency(link_with : core_lib, dependencies: dependencies) + +api_headers = [ + 'linac/rfgap/BaseRfGap.hh', + 'linac/rfgap/BaseRfGap_slow.hh', + 'linac/rfgap/MatrixRfGap.hh', + 'linac/rfgap/RfGapThreePointTTF.hh', + 'linac/rfgap/RfGapThreePointTTF_slow.hh', + 'linac/rfgap/RfGapTTF.hh', + 'linac/rfgap/RfGapTTF_slow.hh', + 'linac/rfgap/SuperFishFieldSource.hh', + 'linac/tracking/linac_tracking.hh', + 'main/pyORBIT_Object.hh', + 'mpi/orbit_mpi.hh', + 'orbit/Apertures/Aperture.hh', + 'orbit/Apertures/BaseAperture.hh', + 'orbit/Apertures/BaseApertureShape.hh', + 'orbit/Apertures/CircleApertureShape.hh', + 'orbit/Apertures/CompositeApertureShape.hh', + 'orbit/Apertures/ConvexApertureShape.hh', + 'orbit/Apertures/EllipseApertureShape.hh', + 'orbit/Apertures/EnergyAperture.hh', + 'orbit/Apertures/PhaseAperture.hh', + 'orbit/Apertures/PyBaseApertureShape.hh', + 'orbit/Apertures/RectangularApertureShape.hh', + 'orbit/Bunch.hh', + 'orbit/BunchDiagnostics/BunchTuneAnalysis.hh', + 'orbit/BunchDiagnostics/BunchTwissAnalysis.hh', + 'orbit/Errors/errorbase.hh', + 'orbit/FieldTracker/FieldTracker.hh', + 'orbit/Impedances/LImpedance.hh', + 'orbit/Impedances/TImpedance.hh', + 'orbit/MaterialInteractions/Collimator.hh', + 'orbit/MaterialInteractions/Foil.hh', + 'orbit/MaterialInteractions/MaterialInteractions.hh', + 'orbit/MaterialInteractions/cross_sections.hh', + 'orbit/MaterialInteractions/numrecipes.hh', + 'orbit/OrbitConst.hh', + 'orbit/ParticlesAttributes/AtomPopulations.hh', + 'orbit/ParticlesAttributes/Evolution.hh', + 'orbit/ParticlesAttributes/LostParticleAttributes.hh', + 'orbit/ParticlesAttributes/ParticleAttributes.hh', + 'orbit/ParticlesAttributes/ParticleAttributesFactory.hh', + 'orbit/ParticlesAttributes/ParticleIdNumber.hh', + 'orbit/ParticlesAttributes/ParticleInitialCoordinates.hh', + 'orbit/ParticlesAttributes/ParticleMacroSize.hh', + 'orbit/ParticlesAttributes/ParticlePhaseAttributes.hh', + 'orbit/ParticlesAttributes/TurnNumberAttributes.hh', + 'orbit/ParticlesAttributes/WaveFunctionAmplitudes.hh', + 'orbit/ParticlesAttributes/part_time.hh', + 'orbit/ParticlesAttributes/pq_coordinates.hh', + 'orbit/RFCavities/Barrier_Cav.hh', + 'orbit/RFCavities/Dual_Harmonic_Cav.hh', + 'orbit/RFCavities/Frequency_Cav.hh', + 'orbit/RFCavities/Harmonic_Cav.hh', + 'orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.hh', + 'orbit/SyncPart.hh', + 'spacecharge/BaseBoundary2D.hh', + 'spacecharge/ForceSolver2D.hh', + 'spacecharge/ForceSolverFFT2D.hh', + 'spacecharge/Grid1D.hh', + 'spacecharge/Grid2D.hh', + 'spacecharge/Grid3D.hh', + 'spacecharge/LSpaceChargeCalc.hh', + 'spacecharge/PoissonSolver2D.hh', + 'spacecharge/PoissonSolver3D.hh', + 'spacecharge/PoissonSolverFFT2D.hh', + 'spacecharge/PoissonSolverFFT3D.hh', + 'spacecharge/ShapedBoundary2D.hh', + 'spacecharge/SpaceChargeCalc2p5D.hh', + 'spacecharge/SpaceChargeCalc2p5Drb.hh', + 'spacecharge/SpaceChargeCalc3D.hh', + 'spacecharge/SpaceChargeCalcSliceBySlice2D.hh', + 'spacecharge/SpaceChargeCalcUnifEllipse.hh', + 'spacecharge/SpaceChargeForceCalc2p5D.hh', + 'spacecharge/UniformEllipsoidFieldCalculator.hh', + 'teapot/MatrixGenerator.hh', + 'teapot/teapotbase.hh', + 'trackerrk4/ExtEffectsContainer.hh', + 'trackerrk4/ExternalEffects.hh', + 'trackerrk4/PyExternalEffects.hh', + 'trackerrk4/RungeKuttaTracker.hh', + 'utils/AttributesBucket.hh', + 'utils/BaseFieldSource.hh', + 'utils/BufferStore.hh', + 'utils/CppPyWrapper.hh', + 'utils/FieldSourceContainer.hh', + 'utils/MathPolynomial.hh', + 'utils/OU_Function.hh', + 'utils/OU_SplineCH.hh', + 'utils/PyBaseFieldSource.hh', + 'utils/Random.hh', + 'utils/StringUtils.hh', + 'utils/bessel.hh', + 'utils/bunch/BunchExtremaCalculator.hh', + 'utils/bunch/InitialCoordsAttrFunctions.hh', + 'utils/bunch/ParticlesWithIdFunctions.hh', + 'utils/bunch/TwissFilteringFunctions.hh', + 'utils/ellipticalint/elliptint.hh', + 'utils/field_sources/DipoleFieldSource.hh', + 'utils/field_sources/LoopFieldSource.hh', + 'utils/field_sources/MagnetFieldSourceGrid3D.hh', + 'utils/field_sources/QuadFieldSource.hh', + 'utils/field_sources/ShiftedFieldSource.hh', + 'utils/harmonic_analysis/HarmonicData.hh', + 'utils/integration/GaussLegendreIntegrator.hh', + 'utils/integration/gauss_legendre_points.hh', + 'utils/matrix/Matrix.hh', + 'utils/matrix/MatrixOperations.hh', + 'utils/matrix/PhaseVector.hh', + 'utils/polynomial/OU_Polynomial.hh', + 'utils/statistics/StatMoments2D.hh', + 'utils/tcomplex.hh', +] + +install_headers(api_headers, subdir : 'pyorbit3', preserve_path : true) + +pc_requires = ['fftw3 >= 3.0.0'] +if get_option('USE_MPI') == 'mpich' + pc_requires += ['mpich >= 4.0.0'] +elif get_option('USE_MPI') == 'ompi' + pc_requires += ['ompi >= 4.0.0'] +endif + +pkgconfig = import('pkgconfig') + +pkgconfig.generate( + name: 'pyorbit3', + description: 'PyORBIT3 core library', + filebase: 'pyorbit3', + version: meson.project_version(), + libraries: core_lib, + requires: pc_requires, + subdirs: 'pyorbit3', + extra_cflags: '-DUSE_MPI=' + use_mpi_flag, + install_dir: get_option('libdir') / 'pkgconfig', +) ext_modules = { - 'orbit_mpi': 'mpi_init.cc', - 'bunch': 'bunch_init.cc', - 'spacecharge': 'spacecharge_init.cc', - 'trackerrk4': 'trackerrk4_init.cc', - 'teapot_base': 'teapot_base_init.cc', - 'linac': 'linac_init.cc', - 'orbit_utils': 'utils_init.cc', - 'aperture': 'aperture_init.cc', - 'foil': 'foil_init.cc', - 'field_sources': 'field_sources_init.cc', - 'rfcavities': 'rfcavities_init.cc', - 'impedances': 'impedances_init.cc', - 'fieldtracker': 'fieldtracker_init.cc', - 'collimator': 'collimator_init.cc', - 'error_base': 'error_base_init.cc', + 'orbit_mpi': files( + 'core/mpi_init.cc', + 'mpi/wrap_orbit_mpi.cc', + 'mpi/wrap_mpi_comm.cc', + 'mpi/wrap_mpi_datatype.cc', + 'mpi/wrap_mpi_request.cc', + 'mpi/wrap_mpi_op.cc', + 'mpi/wrap_mpi_status.cc', + 'mpi/wrap_mpi_group.cc', + ), + 'bunch': files( + 'core/bunch_init.cc', + 'orbit/wrap_bunch.cc', + 'orbit/wrap_syncpart.cc', + 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', + 'orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.cc', + 'orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.cc', + ), + 'spacecharge': files( + 'core/spacecharge_init.cc', + 'spacecharge/wrap_spacecharge.cc', + 'spacecharge/wrap_grid1D.cc', + 'spacecharge/wrap_grid2D.cc', + 'spacecharge/wrap_grid3D.cc', + 'spacecharge/wrap_poissonsolverfft2d.cc', + 'spacecharge/wrap_poissonsolverfft3d.cc', + 'spacecharge/wrap_forcesolverfft2d.cc', + 'spacecharge/wrap_boundary2d.cc', + 'spacecharge/wrap_spacechargecalc2p5d.cc', + 'spacecharge/wrap_spacechargeforcecalc2p5d.cc', + 'spacecharge/wrap_spacechargecalc2p5d_rb.cc', + 'spacecharge/wrap_spacechargecalc_slicebyslice_2D.cc', + 'spacecharge/wrap_lspacechargecalc.cc', + 'spacecharge/wrap_spacechargecalc3d.cc', + 'spacecharge/wrap_uniform_ellipsoid_field_calculator.cc', + 'spacecharge/wrap_spacechargecalc_uniform_ellipse.cc', + ), + 'trackerrk4': files( + 'core/trackerrk4_init.cc', + 'trackerrk4/wrap_trackerrk4.cc', + 'trackerrk4/wrap_runge_kutta_tracker.cc', + 'trackerrk4/wrap_py_external_effects.cc', + 'trackerrk4/wrap_ext_effects_container.cc', + ), + 'teapot_base': files( + 'core/teapot_base_init.cc', + 'teapot/wrap_teapotbase.cc', + 'teapot/wrap_matrix_generator.cc', + ), + 'linac': files( + 'core/linac_init.cc', + 'linac/wrap_linacmodule.cc', + 'linac/tracking/wrap_linac_tracking.cc', + 'linac/rfgap/wrap_BaseRfGap.cc', + 'linac/rfgap/wrap_BaseRfGap_slow.cc', + 'linac/rfgap/wrap_MatrixRfGap.cc', + 'linac/rfgap/wrap_RfGapTTF.cc', + 'linac/rfgap/wrap_RfGapTTF_slow.cc', + 'linac/rfgap/wrap_SuperFishFieldSource.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF.cc', + 'linac/rfgap/wrap_RfGapThreePointTTF_slow.cc', + ), + 'orbit_utils': files( + 'core/utils_init.cc', + 'utils/wrap_utils.cc', + 'utils/matrix/wrap_matrix.cc', + 'utils/matrix/wrap_phase_vector.cc', + 'utils/wrap_py_base_field_source.cc', + 'utils/wrap_field_source_container.cc', + 'utils/wrap_function.cc', + 'utils/wrap_splinech.cc', + 'utils/statistics/wrap_statmoments2d.cc', + 'utils/bunch/wrap_bunch_extrema_calculator.cc', + 'utils/integration/wrap_gauss_legendre_integrator.cc', + 'utils/polynomial/wrap_polynomial.cc', + 'utils/wrap_numrecipes.cc', + 'utils/bunch/wrap_bunch_utils_functions.cc', + 'utils/harmonic_analysis/wrap_harmonic_data.cc', + 'utils/wrap_random.cc', + ), + 'aperture': files( + 'core/aperture_init.cc', + 'orbit/Apertures/wrap_aperture.cc', + 'orbit/Apertures/wrap_TAperture.cc', + 'orbit/Apertures/wrap_PhaseAperture.cc', + 'orbit/Apertures/wrap_EnergyAperture.cc', + 'orbit/Apertures/wrap_BaseAperture.cc', + 'orbit/Apertures/wrap_PyBaseApertureShape.cc', + 'orbit/Apertures/wrap_PrimitiveApertureShape.cc', + 'orbit/Apertures/wrap_CompositeApertureShape.cc', + 'orbit/Apertures/wrap_ConvexApertureShape.cc', + ), + 'foil': files( + 'core/foil_init.cc', + 'orbit/MaterialInteractions/wrap_foil.cc', + ), + 'field_sources': files( + 'core/field_sources_init.cc', + 'utils/field_sources/wrap_field_sources_module.cc', + 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', + 'utils/field_sources/wrap_quad_field_source.cc', + 'utils/field_sources/wrap_dipole_field_source.cc', + 'utils/field_sources/wrap_loop_field_source.cc', + ), + 'rfcavities': files( + 'core/rfcavities_init.cc', + 'orbit/RFCavities/wrap_rfcavities.cc', + 'orbit/RFCavities/wrap_Frequency_Cav.cc', + 'orbit/RFCavities/wrap_Harmonic_Cav.cc', + 'orbit/RFCavities/wrap_Barrier_Cav.cc', + 'orbit/RFCavities/wrap_Dual_Harmonic_Cav.cc', + ), + 'impedances': files( + 'core/impedances_init.cc', + 'orbit/Impedances/wrap_impedances.cc', + 'orbit/Impedances/wrap_LImpedance.cc', + 'orbit/Impedances/wrap_TImpedance.cc', + ), + 'fieldtracker': files( + 'core/fieldtracker_init.cc', + 'orbit/FieldTracker/wrap_fieldtracker.cc', + ), + 'collimator': files( + 'core/collimator_init.cc', + 'orbit/MaterialInteractions/wrap_collimator.cc', + ), + 'error_base': files( + 'core/error_base_init.cc', + 'orbit/Errors/wrap_errorbase.cc', + ), } -base = meson.current_source_dir() + '/core' - -foreach name, src : ext_modules +foreach name, src_list : ext_modules python.extension_module( name, - sources: base / src, + sources: src_list, include_directories: inc, dependencies: [core_dep], install: true, From ae8544cab8f41784e142660580af03b9129c7de1 Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Fri, 19 Jun 2026 10:40:59 -0400 Subject: [PATCH 4/6] Fix runtime dlopen errors by decoupling PyORBIT core logic from wrapper implementation. Previously, we were compiling one, monolithic shared library. In the revised meson.build, I've separated out compilation of the core from python extension modules and removed unnecessary interdependence. Bunch and GridD were reliant on the pyORBIT_MPI_Comm wrapper over MPI_Comm, which coupled C++ core behavior and python wrapper handling thereby preventing separation. Factored out common utility functions to ascertain Python types of pyorbit objects at runtime under src/core/type_accessors.cc. Renamed all instances of "Python.h" -> . This is probably better for Python.h, because the header typically exists at system lib paths, not in the project dir. --- src/core/mpi_init.cc | 4 +- src/core/type_accessors.cc | 65 ++++++ src/linac/rfgap/wrap_BaseRfGap.hh | 2 +- src/linac/rfgap/wrap_BaseRfGap_slow.hh | 2 +- src/linac/rfgap/wrap_MatrixRfGap.hh | 2 +- src/linac/rfgap/wrap_RfGapTTF.hh | 2 +- src/linac/rfgap/wrap_RfGapTTF_slow.hh | 2 +- src/linac/rfgap/wrap_RfGapThreePointTTF.hh | 2 +- .../rfgap/wrap_RfGapThreePointTTF_slow.hh | 2 +- src/linac/rfgap/wrap_SuperFishFieldSource.hh | 2 +- src/linac/tracking/wrap_linac_tracking.cc | 2 +- src/linac/tracking/wrap_linac_tracking.hh | 2 +- src/linac/wrap_linacmodule.hh | 2 +- src/meson.build | 32 ++- src/mpi/orbit_mpi.hh | 2 +- src/mpi/wrap_mpi_comm.cc | 185 ++++++------------ src/mpi/wrap_mpi_comm.hh | 2 +- src/mpi/wrap_orbit_mpi.cc | 2 +- src/mpi/wrap_orbit_mpi.hh | 2 + src/orbit/Apertures/wrap_BaseAperture.hh | 2 +- .../Apertures/wrap_CompositeApertureShape.hh | 2 +- .../Apertures/wrap_ConvexApertureShape.hh | 2 +- src/orbit/Apertures/wrap_EnergyAperture.hh | 2 +- src/orbit/Apertures/wrap_PhaseAperture.hh | 2 +- .../Apertures/wrap_PrimitiveApertureShape.hh | 2 +- .../Apertures/wrap_PyBaseApertureShape.hh | 2 +- src/orbit/Apertures/wrap_TAperture.hh | 2 +- src/orbit/Apertures/wrap_aperture.hh | 2 +- src/orbit/Bunch.cc | 73 ++++--- src/orbit/Bunch.hh | 15 +- .../BunchDiagnostics/BunchTwissAnalysis.cc | 16 +- .../wrap_bunch_tune_analysis.hh | 2 +- .../wrap_bunch_twiss_analysis.hh | 2 +- src/orbit/Errors/wrap_errorbase.cc | 2 +- src/orbit/FieldTracker/wrap_fieldtracker.hh | 2 +- src/orbit/Impedances/wrap_LImpedance.hh | 2 +- src/orbit/Impedances/wrap_TImpedance.hh | 2 +- src/orbit/Impedances/wrap_impedances.hh | 2 +- .../MaterialInteractions/wrap_collimator.hh | 2 +- src/orbit/MaterialInteractions/wrap_foil.hh | 2 +- .../ParticleAttributesFactory.cc | 2 +- src/orbit/RFCavities/wrap_Barrier_Cav.hh | 2 +- .../RFCavities/wrap_Dual_Harmonic_Cav.hh | 2 +- src/orbit/RFCavities/wrap_Frequency_Cav.hh | 2 +- src/orbit/RFCavities/wrap_Harmonic_Cav.hh | 2 +- src/orbit/RFCavities/wrap_rfcavities.hh | 2 +- src/orbit/SyncPart.cc | 6 +- .../SynchPartRedefinitionZdE.cc | 6 +- .../wrap_synch_part_redefinition_z_de.hh | 2 +- src/orbit/wrap_bunch.cc | 67 +++---- src/orbit/wrap_bunch.hh | 4 +- src/orbit/wrap_syncpart.hh | 2 +- src/spacecharge/Grid1D.cc | 6 +- src/spacecharge/Grid1D.hh | 3 +- src/spacecharge/Grid2D.cc | 6 +- src/spacecharge/Grid2D.hh | 3 +- src/spacecharge/Grid3D.cc | 6 +- src/spacecharge/Grid3D.hh | 3 +- src/spacecharge/SpaceChargeCalcUnifEllipse.cc | 4 +- src/spacecharge/SpaceChargeCalcUnifEllipse.hh | 1 - src/spacecharge/wrap_boundary2d.hh | 2 +- src/spacecharge/wrap_forcesolverfft2d.hh | 2 +- src/spacecharge/wrap_grid1D.cc | 2 +- src/spacecharge/wrap_grid1D.hh | 2 +- src/spacecharge/wrap_grid2D.cc | 3 +- src/spacecharge/wrap_grid2D.hh | 2 +- src/spacecharge/wrap_grid3D.cc | 3 +- src/spacecharge/wrap_grid3D.hh | 2 +- src/spacecharge/wrap_lspacechargecalc.hh | 2 +- src/spacecharge/wrap_poissonsolverfft2d.hh | 2 +- src/spacecharge/wrap_poissonsolverfft3d.hh | 2 +- src/spacecharge/wrap_spacecharge.cc | 8 - src/spacecharge/wrap_spacecharge.hh | 2 +- src/spacecharge/wrap_spacechargecalc2p5d.hh | 2 +- .../wrap_spacechargecalc2p5d_rb.hh | 2 +- src/spacecharge/wrap_spacechargecalc3d.hh | 2 +- .../wrap_spacechargecalc_slicebyslice_2D.hh | 2 +- .../wrap_spacechargecalc_uniform_ellipse.hh | 2 +- .../wrap_spacechargeforcecalc2p5d.hh | 2 +- ...wrap_uniform_ellipsoid_field_calculator.hh | 2 +- src/teapot/wrap_matrix_generator.hh | 2 +- src/teapot/wrap_teapotbase.cc | 2 +- src/trackerrk4/ExtEffectsContainer.hh | 2 +- src/trackerrk4/PyExternalEffects.hh | 2 +- src/trackerrk4/wrap_ext_effects_container.hh | 2 +- src/trackerrk4/wrap_py_external_effects.hh | 2 +- src/trackerrk4/wrap_runge_kutta_tracker.hh | 2 +- src/trackerrk4/wrap_trackerrk4.cc | 8 - src/trackerrk4/wrap_trackerrk4.hh | 2 +- src/utils/CppPyWrapper.hh | 2 +- src/utils/FieldSourceContainer.hh | 2 +- src/utils/PyBaseFieldSource.hh | 2 +- src/utils/bunch/BunchExtremaCalculator.cc | 12 +- src/utils/bunch/InitialCoordsAttrFunctions.cc | 14 +- src/utils/bunch/ParticlesWithIdFunctions.cc | 18 +- .../bunch/wrap_bunch_extrema_calculator.hh | 2 +- src/utils/bunch/wrap_bunch_utils_functions.hh | 2 +- src/utils/field_sources/ShiftedFieldSource.cc | 2 +- .../field_sources/wrap_dipole_field_source.hh | 2 +- .../wrap_field_sources_module.hh | 2 +- .../field_sources/wrap_loop_field_source.hh | 2 +- .../wrap_magnetic_field_source_grid3d.hh | 2 +- .../field_sources/wrap_quad_field_source.hh | 2 +- .../harmonic_analysis/wrap_harmonic_data.hh | 2 +- .../wrap_gauss_legendre_integrator.hh | 2 +- src/utils/matrix/wrap_matrix.hh | 2 +- src/utils/matrix/wrap_phase_vector.hh | 2 +- src/utils/polynomial/wrap_polynomial.hh | 2 +- src/utils/statistics/StatMoments2D.cc | 10 +- src/utils/statistics/StatMoments2D.hh | 3 +- src/utils/statistics/wrap_statmoments2d.cc | 2 +- src/utils/statistics/wrap_statmoments2d.hh | 2 +- src/utils/wrap_field_source_container.hh | 2 +- src/utils/wrap_function.hh | 2 +- src/utils/wrap_numrecipes.hh | 2 +- src/utils/wrap_py_base_field_source.hh | 2 +- src/utils/wrap_random.hh | 2 +- src/utils/wrap_splinech.hh | 2 +- src/utils/wrap_utils.cc | 9 - src/utils/wrap_utils.hh | 2 +- 120 files changed, 381 insertions(+), 394 deletions(-) create mode 100644 src/core/type_accessors.cc diff --git a/src/core/mpi_init.cc b/src/core/mpi_init.cc index 19fcf616..bf3e796a 100644 --- a/src/core/mpi_init.cc +++ b/src/core/mpi_init.cc @@ -1,6 +1,6 @@ -#include "Python.h" +#include #include "wrap_orbit_mpi.hh" PyMODINIT_FUNC PyInit_orbit_mpi(void) { return wrap_orbit_mpi::initorbit_mpi(); -} \ No newline at end of file +} diff --git a/src/core/type_accessors.cc b/src/core/type_accessors.cc new file mode 100644 index 00000000..31b91134 --- /dev/null +++ b/src/core/type_accessors.cc @@ -0,0 +1,65 @@ +#include + +#include "wrap_bunch.hh" +#include "wrap_spacecharge.hh" +#include "wrap_mpi_comm.hh" +#include "wrap_utils.hh" +#include "wrap_trackerrk4.hh" + +extern "C" { + +namespace wrap_orbit_bunch { + +PyObject* getBunchType(const char* name){ + PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); + PyObject* pyType = PyObject_GetAttrString(mod,name); + Py_DECREF(mod); + Py_DECREF(pyType); + return pyType; +} + +} + +PyObject* getSpaceChargeType(const char* name){ + PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); + PyObject* pyType = PyObject_GetAttrString(mod,name); + Py_DECREF(mod); + Py_DECREF(pyType); + return pyType; +} + +namespace wrap_orbit_mpi_comm { + +PyObject* getMPI_CommType(const char* name){ + PyObject* mod = PyImport_ImportModule("orbit.core.orbit_mpi"); + PyObject* mpi_comm_mod = PyObject_GetAttrString(mod,"mpi_comm"); + PyObject* pyType = PyObject_GetAttrString(mpi_comm_mod,name); + Py_DECREF(mpi_comm_mod); + Py_DECREF(mod); + Py_DECREF(pyType); + return pyType; +} + +} + +namespace wrap_orbit_utils { + +PyObject* getOrbitUtilsType(const char* name){ + PyObject* mod = PyImport_ImportModule(const_cast("orbit.core.orbit_utils")); + PyObject* pyType = PyObject_GetAttrString(mod,name); + Py_DECREF(mod); + Py_DECREF(pyType); + return pyType; +} + +} + +PyObject* getTrackerRK4Type(const char* name){ + PyObject* mod = PyImport_ImportModule("orbit.core.trackerrk4"); + PyObject* pyType = PyObject_GetAttrString(mod,name); + Py_DECREF(mod); + Py_DECREF(pyType); + return pyType; +} + +} diff --git a/src/linac/rfgap/wrap_BaseRfGap.hh b/src/linac/rfgap/wrap_BaseRfGap.hh index 588ec5d5..6960adfd 100644 --- a/src/linac/rfgap/wrap_BaseRfGap.hh +++ b/src/linac/rfgap/wrap_BaseRfGap.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BASE_RF_GAP_H #define WRAP_BASE_RF_GAP_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_BaseRfGap_slow.hh b/src/linac/rfgap/wrap_BaseRfGap_slow.hh index 54b11437..5b2908d6 100644 --- a/src/linac/rfgap/wrap_BaseRfGap_slow.hh +++ b/src/linac/rfgap/wrap_BaseRfGap_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BASE_RF_GAP_SLOW_H #define WRAP_BASE_RF_GAP_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_MatrixRfGap.hh b/src/linac/rfgap/wrap_MatrixRfGap.hh index 745dd3f1..8086e6ff 100644 --- a/src/linac/rfgap/wrap_MatrixRfGap.hh +++ b/src/linac/rfgap/wrap_MatrixRfGap.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MATRIX_RF_GAP_H #define WRAP_MATRIX_RF_GAP_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapTTF.hh b/src/linac/rfgap/wrap_RfGapTTF.hh index 190061d4..41acb227 100644 --- a/src/linac/rfgap/wrap_RfGapTTF.hh +++ b/src/linac/rfgap/wrap_RfGapTTF.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_TTF_H #define WRAP_RF_GAP_TTF_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapTTF_slow.hh b/src/linac/rfgap/wrap_RfGapTTF_slow.hh index 2c7a6a8f..442e556d 100644 --- a/src/linac/rfgap/wrap_RfGapTTF_slow.hh +++ b/src/linac/rfgap/wrap_RfGapTTF_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_TTF_SLOW_H #define WRAP_RF_GAP_TTF_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF.hh b/src/linac/rfgap/wrap_RfGapThreePointTTF.hh index 2f9a9611..3e1d3e04 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF.hh +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_THREE_POINT_TTF_H #define WRAP_RF_GAP_THREE_POINT_TTF_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh index 62f99b3c..eabae2e4 100644 --- a/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh +++ b/src/linac/rfgap/wrap_RfGapThreePointTTF_slow.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RF_GAP_THREE_POINT_TTF_SLOW_H #define WRAP_RF_GAP_THREE_POINT_TTF_SLOW_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/rfgap/wrap_SuperFishFieldSource.hh b/src/linac/rfgap/wrap_SuperFishFieldSource.hh index 474817c6..23b5ba93 100644 --- a/src/linac/rfgap/wrap_SuperFishFieldSource.hh +++ b/src/linac/rfgap/wrap_SuperFishFieldSource.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SUPER_FISH_RF_FIELD_SOURCE_H #define WRAP_SUPER_FISH_RF_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/linac/tracking/wrap_linac_tracking.cc b/src/linac/tracking/wrap_linac_tracking.cc index 579d9477..5c54fff1 100644 --- a/src/linac/tracking/wrap_linac_tracking.cc +++ b/src/linac/tracking/wrap_linac_tracking.cc @@ -1,4 +1,4 @@ -#include "Python.h" +#include #include "orbit_mpi.hh" #include "pyORBIT_Object.hh" diff --git a/src/linac/tracking/wrap_linac_tracking.hh b/src/linac/tracking/wrap_linac_tracking.hh index db48ced3..0bbfec87 100644 --- a/src/linac/tracking/wrap_linac_tracking.hh +++ b/src/linac/tracking/wrap_linac_tracking.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LINAC_TRACKING_H #define WRAP_LINAC_TRACKING_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/linac/wrap_linacmodule.hh b/src/linac/wrap_linacmodule.hh index 62fd8d56..75b83f66 100644 --- a/src/linac/wrap_linacmodule.hh +++ b/src/linac/wrap_linacmodule.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LINAC_H #define WRAP_LINAC_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/meson.build b/src/meson.build index 84d484f6..e03091ac 100644 --- a/src/meson.build +++ b/src/meson.build @@ -1,10 +1,7 @@ -# Add Python installation details python = import('python').find_installation('python3', pure: false) -# Add C++ compiler details cpp = meson.get_compiler('cpp') -# Add -march=native if the compiler supports it if cpp.has_argument('-march=native') add_project_arguments('-march=native', language: 'cpp') endif @@ -14,8 +11,16 @@ dependencies = [] dependencies += python.dependency() dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) -# Detecting if MPICH or OPENMPI are installed and enabling support if present +py_link_args = [] + +if host_machine.system() == 'darwin' + # The unresolved symbols will be resolved once the Python interpreter loads libpyorbit. + # The linker on MacOS is a bit more strict, so we need to explicitly tell it that + # symbols from libpython will be nont resolvable for now. + py_link_args += ['-Wl,-undefined,dynamic_lookup'] +endif +# Detecting if MPICH or OPENMPI are installed and enabling support if present mpi_use = get_option('USE_MPI') use_mpi_flag = '0' @@ -192,11 +197,11 @@ inc = include_directories([ ]) core_lib = library( - 'pyorbit3_core', + 'pyorbit3', sources: sources, include_directories: inc, dependencies: dependencies, - override_options: ['b_lundef=false'], + link_args: py_link_args, install: true, ) @@ -351,6 +356,7 @@ ext_modules = { ), 'bunch': files( 'core/bunch_init.cc', + 'core/type_accessors.cc', 'orbit/wrap_bunch.cc', 'orbit/wrap_syncpart.cc', 'orbit/BunchDiagnostics/wrap_bunch_tune_analysis.cc', @@ -359,6 +365,7 @@ ext_modules = { ), 'spacecharge': files( 'core/spacecharge_init.cc', + 'core/type_accessors.cc', 'spacecharge/wrap_spacecharge.cc', 'spacecharge/wrap_grid1D.cc', 'spacecharge/wrap_grid2D.cc', @@ -385,11 +392,13 @@ ext_modules = { ), 'teapot_base': files( 'core/teapot_base_init.cc', + 'core/type_accessors.cc', 'teapot/wrap_teapotbase.cc', 'teapot/wrap_matrix_generator.cc', ), 'linac': files( 'core/linac_init.cc', + 'core/type_accessors.cc', 'linac/wrap_linacmodule.cc', 'linac/tracking/wrap_linac_tracking.cc', 'linac/rfgap/wrap_BaseRfGap.cc', @@ -403,6 +412,7 @@ ext_modules = { ), 'orbit_utils': files( 'core/utils_init.cc', + 'core/type_accessors.cc', 'utils/wrap_utils.cc', 'utils/matrix/wrap_matrix.cc', 'utils/matrix/wrap_phase_vector.cc', @@ -421,6 +431,7 @@ ext_modules = { ), 'aperture': files( 'core/aperture_init.cc', + 'core/type_accessors.cc', 'orbit/Apertures/wrap_aperture.cc', 'orbit/Apertures/wrap_TAperture.cc', 'orbit/Apertures/wrap_PhaseAperture.cc', @@ -433,10 +444,12 @@ ext_modules = { ), 'foil': files( 'core/foil_init.cc', + 'core/type_accessors.cc', 'orbit/MaterialInteractions/wrap_foil.cc', ), 'field_sources': files( 'core/field_sources_init.cc', + 'core/type_accessors.cc', 'utils/field_sources/wrap_field_sources_module.cc', 'utils/field_sources/wrap_magnetic_field_source_grid3d.cc', 'utils/field_sources/wrap_quad_field_source.cc', @@ -445,6 +458,7 @@ ext_modules = { ), 'rfcavities': files( 'core/rfcavities_init.cc', + 'core/type_accessors.cc', 'orbit/RFCavities/wrap_rfcavities.cc', 'orbit/RFCavities/wrap_Frequency_Cav.cc', 'orbit/RFCavities/wrap_Harmonic_Cav.cc', @@ -453,16 +467,19 @@ ext_modules = { ), 'impedances': files( 'core/impedances_init.cc', + 'core/type_accessors.cc', 'orbit/Impedances/wrap_impedances.cc', 'orbit/Impedances/wrap_LImpedance.cc', 'orbit/Impedances/wrap_TImpedance.cc', ), 'fieldtracker': files( 'core/fieldtracker_init.cc', + 'core/type_accessors.cc', 'orbit/FieldTracker/wrap_fieldtracker.cc', ), 'collimator': files( 'core/collimator_init.cc', + 'core/type_accessors.cc', 'orbit/MaterialInteractions/wrap_collimator.cc', ), 'error_base': files( @@ -476,7 +493,8 @@ foreach name, src_list : ext_modules name, sources: src_list, include_directories: inc, - dependencies: [core_dep], + link_with: core_lib, + dependencies: dependencies, install: true, subdir: 'orbit/core', ) diff --git a/src/mpi/orbit_mpi.hh b/src/mpi/orbit_mpi.hh index 4f07ccf8..a1009529 100644 --- a/src/mpi/orbit_mpi.hh +++ b/src/mpi/orbit_mpi.hh @@ -1,4 +1,4 @@ -#include "Python.h" +#include #ifndef ORBIT_MPI_INCLUDE #define ORBIT_MPI_INCLUDE diff --git a/src/mpi/wrap_mpi_comm.cc b/src/mpi/wrap_mpi_comm.cc index 9e4f98a5..ca27414c 100644 --- a/src/mpi/wrap_mpi_comm.cc +++ b/src/mpi/wrap_mpi_comm.cc @@ -1,16 +1,4 @@ -/////////////////////////////////////////////////////////////////////////// -// -// INCLUDE FILES -// -/////////////////////////////////////////////////////////////////////////// #include "orbit_mpi.hh" - -//this header is from Python package -#include "structmember.h" - -//c++ header for cerr and cout -#include - #include "wrap_mpi_comm.hh" namespace wrap_orbit_mpi_comm{ @@ -20,13 +8,8 @@ namespace wrap_orbit_mpi_comm{ #ifdef __cplusplus extern "C" { #endif - //--------------------------------------------------------- - //Python MPI_Comm class definition - //--------------------------------------------------------- - //constructor for python class wrapping MPI_Comm instance - //It never will be called directly - static PyObject* mpi_comm_new(PyTypeObject *type, PyObject *args, PyObject *kwds) + static PyObject* mpi_comm_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) { pyORBIT_MPI_Comm* self; self = (pyORBIT_MPI_Comm *) type->tp_alloc(type, 0); @@ -34,105 +17,85 @@ extern "C" { return (PyObject *) self; } - //initializator for python MPI_Comm class - //this is implementation of the __init__ method - static int mpi_comm_init(pyORBIT_MPI_Comm *self, PyObject *args, PyObject *kwds){ - if(PyTuple_Size(args) != 0){ - error("MPI_Comm constructor cannot have an input parameter."); - } - return 0; - } - - //feeing the mpi comm in the python MPI_Comm class - static PyObject* mpi_comm_free(PyObject *self, PyObject *args){ - pyORBIT_MPI_Comm* pyMPI_Comm = (pyORBIT_MPI_Comm*) self; + static int mpi_comm_init(pyORBIT_MPI_Comm *Py_UNUSED(self), PyObject *args, PyObject *Py_UNUSED(kwds)){ + if(PyTuple_Size(args) != 0){ + error("MPI_Comm constructor cannot have an input parameter."); + } + return 0; + } + + static PyObject* mpi_comm_free(PyObject *self, PyObject *Py_UNUSED(ignored)){ + pyORBIT_MPI_Comm* pyMPI_Comm = (pyORBIT_MPI_Comm*) self; if(pyMPI_Comm->comm != MPI_COMM_WORLD && pyMPI_Comm->comm != MPI_COMM_SELF){ ORBIT_MPI_Comm_free(&pyMPI_Comm->comm); } pyMPI_Comm->comm = MPI_COMM_WORLD; - Py_INCREF(Py_None); - return Py_None; - } - - //----------------------------------------------------- - //destructor for python MPI_Comm class. - //----------------------------------------------------- - //this is implementation of the __del__ method - static void mpi_comm_del(pyORBIT_MPI_Comm* self){ - //std::cerr<<"The MPI_Comm __del__ has been called!"<comm; if(comm != MPI_COMM_NULL && comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF){ ORBIT_MPI_Comm_free(&comm); } self->ob_base.ob_type->tp_free((PyObject*)self); - } - - // defenition of the methods of the python MPI_Comm wrapper class - // they will be vailable from python level - static PyMethodDef MPI_CommClassMethods[] = { - //{ "test", MPI_Comm_test ,METH_VARARGS,"document string"}, - { "free", mpi_comm_free ,METH_VARARGS,"Free MPI communicator."}, - {NULL} - }; - - // defenition of the memebers of the python MPI_Comm wrapper class - // they will be vailable from python level + } + + static PyMethodDef MPI_CommClassMethods[] = { + { "free", mpi_comm_free ,METH_NOARGS,"Free MPI communicator."}, + {NULL} + }; + static PyMemberDef MPI_CommClassMembers[] = { {NULL} }; - //new python SyncPart wrapper type definition - static PyTypeObject pyORBIT_MPI_Comm_Type = { + PyTypeObject pyORBIT_MPI_Comm_Type = { PyVarObject_HEAD_INIT(NULL, 0) - "MPI_Comm", /*tp_name*/ - sizeof(pyORBIT_MPI_Comm), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor) mpi_comm_del , /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "The MPI_Comm python wrapper", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - MPI_CommClassMethods, /* tp_methods */ - MPI_CommClassMembers, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc) mpi_comm_init, /* tp_init */ - 0, /* tp_alloc */ - mpi_comm_new, /* tp_new */ + "MPI_Comm", + sizeof(pyORBIT_MPI_Comm), + 0, + (destructor) mpi_comm_del, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, + "The MPI_Comm python wrapper", + 0, + 0, + 0, + 0, + 0, + 0, + MPI_CommClassMethods, + MPI_CommClassMembers, + 0, + 0, + 0, + 0, + 0, + 0, + (initproc) mpi_comm_init, + 0, + mpi_comm_new, }; - //-------------------------------------------------- - //Initialization function of the MPI_Comm class - //It will be called from orbit_mpi wrapper initialization - //-------------------------------------------------- - void init_orbit_mpi_comm(PyObject* module){ + void init_orbit_mpi_comm(PyObject* module){ if (PyType_Ready(&pyORBIT_MPI_Comm_Type) < 0) return; Py_INCREF(&pyORBIT_MPI_Comm_Type); - //we put Py_INCREF(...) because PyModule_AddObject() steal the reference - PyObject * comm_module = PyModule_New("mpi_comm"); PyModule_AddObject(comm_module, "MPI_Comm", (PyObject *)&pyORBIT_MPI_Comm_Type); Py_INCREF(comm_module); @@ -149,16 +112,13 @@ extern "C" { pyMPI_Comm_NULL->comm = MPI_COMM_NULL; Py_INCREF((PyObject *) pyMPI_Comm_NULL); - PyModule_AddObject(comm_module, "MPI_COMM_WORLD", (PyObject *) pyMPI_Comm_WORLD); - PyModule_AddObject(comm_module, "MPI_COMM_SELF", (PyObject *) pyMPI_Comm_SELF); - PyModule_AddObject(comm_module, "MPI_COMM_NULL", (PyObject *) pyMPI_Comm_NULL); + PyModule_AddObject(comm_module, "MPI_COMM_WORLD", (PyObject *) pyMPI_Comm_WORLD); + PyModule_AddObject(comm_module, "MPI_COMM_SELF", (PyObject *) pyMPI_Comm_SELF); + PyModule_AddObject(comm_module, "MPI_COMM_NULL", (PyObject *) pyMPI_Comm_NULL); PyModule_AddObject(module, "mpi_comm", comm_module); } - //----------------------------------------------------------- - //The function that will be exposed as C/C++ API for MPI_Comm - //----------------------------------------------------------- pyORBIT_MPI_Comm* newMPI_Comm(){ pyORBIT_MPI_Comm* pyMPI_Comm = PyObject_New(pyORBIT_MPI_Comm,&pyORBIT_MPI_Comm_Type); pyMPI_Comm->comm = MPI_COMM_WORLD; @@ -170,25 +130,8 @@ extern "C" { Py_DECREF(pyMPI_Comm); } - PyObject* getMPI_CommType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.orbit_mpi"); - PyObject* mpi_comm_mod = PyObject_GetAttrString(mod,"mpi_comm"); - PyObject* pyType = PyObject_GetAttrString(mpi_comm_mod,name); - Py_DECREF(mpi_comm_mod); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif -//end of namespace wrap_orbit_mpi_comm } - -/////////////////////////////////////////////////////////////////////////// -// -// END OF FILE -// -/////////////////////////////////////////////////////////////////////////// diff --git a/src/mpi/wrap_mpi_comm.hh b/src/mpi/wrap_mpi_comm.hh index 9b06b544..7328e210 100644 --- a/src/mpi/wrap_mpi_comm.hh +++ b/src/mpi/wrap_mpi_comm.hh @@ -12,7 +12,7 @@ extern "C" { #endif - namespace wrap_orbit_mpi_comm{ + namespace wrap_orbit_mpi_comm { void init_orbit_mpi_comm(PyObject* module); //The function that will be exposed as C/C++ API for MPI_Comm diff --git a/src/mpi/wrap_orbit_mpi.cc b/src/mpi/wrap_orbit_mpi.cc index f83ff846..658232ed 100644 --- a/src/mpi/wrap_orbit_mpi.cc +++ b/src/mpi/wrap_orbit_mpi.cc @@ -1,5 +1,5 @@ #define PY_SSIZE_T_CLEAN -#include "Python.h" +#include #include "orbit_mpi.hh" #include diff --git a/src/mpi/wrap_orbit_mpi.hh b/src/mpi/wrap_orbit_mpi.hh index 2f4cc15f..16d769ed 100644 --- a/src/mpi/wrap_orbit_mpi.hh +++ b/src/mpi/wrap_orbit_mpi.hh @@ -1,3 +1,5 @@ +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/orbit/Apertures/wrap_BaseAperture.hh b/src/orbit/Apertures/wrap_BaseAperture.hh index bd6d0c13..6df9220e 100644 --- a/src/orbit/Apertures/wrap_BaseAperture.hh +++ b/src/orbit/Apertures/wrap_BaseAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_BASE_APERTURE_HH_ #define WRAP_ORBIT_BASE_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_CompositeApertureShape.hh b/src/orbit/Apertures/wrap_CompositeApertureShape.hh index a2a4c165..63d46246 100644 --- a/src/orbit/Apertures/wrap_CompositeApertureShape.hh +++ b/src/orbit/Apertures/wrap_CompositeApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_COMPOSITE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_COMPOSITE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_ConvexApertureShape.hh b/src/orbit/Apertures/wrap_ConvexApertureShape.hh index 92a67841..b4e9cfa9 100644 --- a/src/orbit/Apertures/wrap_ConvexApertureShape.hh +++ b/src/orbit/Apertures/wrap_ConvexApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_CONVEX_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_CONVEX_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_EnergyAperture.hh b/src/orbit/Apertures/wrap_EnergyAperture.hh index b022d90e..acf0525d 100644 --- a/src/orbit/Apertures/wrap_EnergyAperture.hh +++ b/src/orbit/Apertures/wrap_EnergyAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_ENERGY_APERTURE_HH_ #define WRAP_ORBIT_ENERGY_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PhaseAperture.hh b/src/orbit/Apertures/wrap_PhaseAperture.hh index 921b1e27..e438bb4f 100644 --- a/src/orbit/Apertures/wrap_PhaseAperture.hh +++ b/src/orbit/Apertures/wrap_PhaseAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PHASE_APERTURE_HH_ #define WRAP_ORBIT_PHASE_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh b/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh index 627dd19b..45fc9b77 100644 --- a/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh +++ b/src/orbit/Apertures/wrap_PrimitiveApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PRIMITIVE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_PRIMITIVE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_PyBaseApertureShape.hh b/src/orbit/Apertures/wrap_PyBaseApertureShape.hh index 41299cc5..46527930 100644 --- a/src/orbit/Apertures/wrap_PyBaseApertureShape.hh +++ b/src/orbit/Apertures/wrap_PyBaseApertureShape.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_PY_BASE_APERTURE_SHAPE_HH_ #define WRAP_ORBIT_PY_BASE_APERTURE_SHAPE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_TAperture.hh b/src/orbit/Apertures/wrap_TAperture.hh index 4d49cf5e..b028e599 100644 --- a/src/orbit/Apertures/wrap_TAperture.hh +++ b/src/orbit/Apertures/wrap_TAperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_APERTURE_HH_ #define WRAP_ORBIT_APERTURE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Apertures/wrap_aperture.hh b/src/orbit/Apertures/wrap_aperture.hh index 6de0fef3..81609f59 100644 --- a/src/orbit/Apertures/wrap_aperture.hh +++ b/src/orbit/Apertures/wrap_aperture.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_APERTURE_MODULE_HH_ #define WRAP_ORBIT_APERTURE_MODULE_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Bunch.cc b/src/orbit/Bunch.cc index 8a2a2714..08c32684 100644 --- a/src/orbit/Bunch.cc +++ b/src/orbit/Bunch.cc @@ -56,15 +56,15 @@ Bunch::Bunch(): CppPyWrapper(NULL) } //for MPI - pyComm_Local = wrap_orbit_mpi_comm::newMPI_Comm(); + comm_ = MPI_COMM_WORLD; rank_MPI = 0; size_MPI = 1; iMPIini = 0; ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ - ORBIT_MPI_Comm_size(pyComm_Local->comm, &size_MPI); - ORBIT_MPI_Comm_rank(pyComm_Local->comm, &rank_MPI); + ORBIT_MPI_Comm_size(comm_, &size_MPI); + ORBIT_MPI_Comm_rank(comm_, &rank_MPI); } //data members related to the ParticleAttributes @@ -103,8 +103,7 @@ Bunch::~Bunch() //delete synchronous particle instance delete syncPart; - //delete the python instance of the mpi communicator - wrap_orbit_mpi_comm::freeMPI_Comm(this->pyComm_Local); + //MPI communicator is handled by the caller; no cleanup needed } AttributesBucket* Bunch::getBunchAttributes(){ @@ -209,7 +208,7 @@ void Bunch::initBunchAttributes(const char* fileName){ } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -249,18 +248,18 @@ void Bunch::initBunchAttributes(const char* fileName){ if(size_MPI > 1){ - ORBIT_MPI_Bcast (&stop_ind,1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast (&def_found_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&stop_ind,1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast (&def_found_ind,1, MPI_INT, 0, comm_ ); } if(stop_ind == 0 && def_found_ind == 1){ if(size_MPI > 1){ int strLength = strlen(str.c_str()); - ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, comm_ ); int buff_index = 0; char* char_tmp = BufferStore::getBufferStore()->getFreeCharArr(buff_index,strLength+1); strcpy(char_tmp, str.c_str()); - ORBIT_MPI_Bcast ( char_tmp, strLength+1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( char_tmp, strLength+1, MPI_CHAR, 0, comm_ ); std::string str_new(char_tmp); BufferStore::getBufferStore()->setUnusedCharArr(buff_index); StringUtils::Tokenize(str_new,v_str); @@ -856,7 +855,7 @@ int Bunch::getSizeGlobal() } else{ ORBIT_MPI_Allreduce(&nSize,&sizeGlobal,1, - MPI_INT,MPI_SUM,pyComm_Local->comm); + MPI_INT,MPI_SUM,comm_); return sizeGlobal; } } @@ -985,7 +984,7 @@ void Bunch::print(std::ostream& Out) if(i==rank_MPI){nSizeArr[i]=nSize;} } ORBIT_MPI_Allreduce(nSizeArr,nSizeArr_MPI,size_MPI, - MPI_INT,MPI_SUM,pyComm_Local->comm); + MPI_INT,MPI_SUM,comm_); //at this point all CPUs know about number of macro-particles on each CPU @@ -1023,11 +1022,11 @@ void Bunch::print(std::ostream& Out) j_count++; } ORBIT_MPI_Send(dump_arr, (nDimAndAttr)*nSizeChank, MPI_DOUBLE, 0, - 1111, pyComm_Local->comm); + 1111, comm_); } if(rank_MPI == 0){ ORBIT_MPI_Recv(dump_arr, (nDimAndAttr)*nSizeChank, MPI_DOUBLE, i, - 1111, pyComm_Local->comm, &statusMPI); + 1111, comm_, &statusMPI); for( int j = 0; j < (j_stop - j_start); j++){ int flg = (int) dump_arr[(nDimAndAttr)*j + 6]; if(flg > 0){ @@ -1124,7 +1123,7 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -1196,10 +1195,10 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast ( &nT, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &error_ind, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &nn, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( arr_0, chunk_size*(nDimAndAttr) , MPI_DOUBLE, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nT, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &error_ind, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &nn, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( arr_0, chunk_size*(nDimAndAttr) , MPI_DOUBLE, 0, comm_ ); } if(error_ind > 0){ @@ -1229,7 +1228,7 @@ int Bunch::readBunchCoords(const char* fileName, int nParts) } if(size_MPI > 1){ - ORBIT_MPI_Bcast ( &info_stop, 1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &info_stop, 1, MPI_INT, 0, comm_ ); } } @@ -1317,7 +1316,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, } if(size_MPI > 1){ - ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast (&error_ind,1, MPI_INT, 0, comm_ ); } if(error_ind > 0){ @@ -1370,8 +1369,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, if(strLength < ln_str) { strLength = ln_str;} } - ORBIT_MPI_Bcast ( &nTypes, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nTypes, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( &strLength,1, MPI_INT, 0, comm_ ); if(nTypes == 0) return 0; @@ -1380,8 +1379,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, strcpy(char_tmp, str.c_str()); int ln_str = strlen(str.c_str()); - ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, comm_ ); std::string str_new(char_tmp); StringUtils::Tokenize(str_new,v_str); @@ -1393,7 +1392,7 @@ int Bunch::readParticleAttributesNames(const char* fileName, //spreading all attr. dictionaries across all CPUs int nDicts = v_str_part_attr.size(); - ORBIT_MPI_Bcast ( &nDicts, 1, MPI_INT, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &nDicts, 1, MPI_INT, 0, comm_ ); if(rank_MPI != 0){ v_str_part_attr.clear(); } @@ -1403,8 +1402,8 @@ int Bunch::readParticleAttributesNames(const char* fileName, ln_str = strlen(v_str_part_attr[i].c_str()); strcpy(char_tmp, v_str_part_attr[i].c_str()); } - ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, pyComm_Local->comm ); - ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, pyComm_Local->comm ); + ORBIT_MPI_Bcast ( &ln_str, 1, MPI_INT, 0, comm_ ); + ORBIT_MPI_Bcast ( char_tmp,ln_str +1, MPI_CHAR, 0, comm_ ); std::string str_tmp(char_tmp); if(rank_MPI != 0){ v_str_part_attr.push_back(str_tmp); @@ -1675,17 +1674,17 @@ void Bunch::restoreAllParticleAttributesFromMemory(){ attrCntrMapTemp.clear(); } -pyORBIT_MPI_Comm* Bunch::getMPI_Comm_Local(){ - return pyComm_Local; +MPI_Comm Bunch::getMPI_Comm_Local() const noexcept { + return comm_; } -void Bunch::setMPI_Comm_Local(pyORBIT_MPI_Comm* pyComm_Local){ - wrap_orbit_mpi_comm::freeMPI_Comm(this->pyComm_Local); - this->pyComm_Local = pyComm_Local; - Py_INCREF((PyObject *) this->pyComm_Local); - if(iMPIini > 0){ - ORBIT_MPI_Comm_size(pyComm_Local->comm, &size_MPI); - ORBIT_MPI_Comm_rank(pyComm_Local->comm, &rank_MPI); +void Bunch::setMPI_Comm_Local(MPI_Comm comm){ + // wrap_orbit_mpi_comm::freeMPI_Comm(comm_); + comm_ = comm; + // Py_INCREF((PyObject *) this->comm_); + if(iMPIini > 0) { + ORBIT_MPI_Comm_size(comm, &size_MPI); + ORBIT_MPI_Comm_rank(comm, &rank_MPI); } } diff --git a/src/orbit/Bunch.hh b/src/orbit/Bunch.hh index 9f525b86..f5cd0a0b 100644 --- a/src/orbit/Bunch.hh +++ b/src/orbit/Bunch.hh @@ -21,15 +21,11 @@ // /////////////////////////////////////////////////////////////////////////// #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" #include -#include #include -#include #include -#include #include #include @@ -40,8 +36,6 @@ #include "AttributesBucket.hh" #include "CppPyWrapper.hh" -using namespace std; - #ifndef BUNCH_H #define BUNCH_H /////////////////////////////////////////////////////////////////////////// @@ -191,8 +185,8 @@ public: void addParticlesTo(Bunch* bunch); //Parallel case - pyORBIT_MPI_Comm* getMPI_Comm_Local(); - void setMPI_Comm_Local(pyORBIT_MPI_Comm* pyComm_Local); + MPI_Comm getMPI_Comm_Local() const noexcept; + void setMPI_Comm_Local(MPI_Comm comm); int getMPI_Size(); int getMPI_Rank(); @@ -285,10 +279,7 @@ protected: int rank_MPI; int size_MPI; - pyORBIT_MPI_Comm* pyComm_Local; - - //reference to the python wrapping class instance - PyObject* py_wrapper; + MPI_Comm comm_; }; diff --git a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc index 0a361326..8fea7169 100644 --- a/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc +++ b/src/orbit/BunchDiagnostics/BunchTwissAnalysis.cc @@ -108,15 +108,15 @@ void BunchTwissAnalysis::analyzeBunch(Bunch* bunch){ } int count_MPI = 0; - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()); count = count_MPI; double total_macrosize_MPI = 0.; - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; - ORBIT_MPI_Allreduce(avg_arr,avg_arr_MPI,6,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(corr_arr,corr_arr_MPI,36,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(avg_arr,avg_arr_MPI,6,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(corr_arr,corr_arr_MPI,36,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ for(int i = 0; i < 6; i++){ @@ -189,11 +189,11 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; double xAvg_MPI = 0; - ORBIT_MPI_Allreduce(&xAvg,&xAvg_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&xAvg,&xAvg_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ xAvg = xAvg_MPI/total_macrosize; } @@ -294,7 +294,7 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; //if( nMPIsize_ > 1){ @@ -310,7 +310,7 @@ void BunchTwissAnalysis::computeBunchMoments(Bunch* bunch, int order, int disper //MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); - ORBIT_MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE, MPI_SUM, bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(buff_0, buff_1, count, MPI_DOUBLE, MPI_SUM, bunch->getMPI_Comm_Local()); count = 0; for(j=0; j<_order+1; j++){ diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh index af0f0c0a..36fc94cc 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh +++ b/src/orbit/BunchDiagnostics/wrap_bunch_tune_analysis.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BUNCH_TUNE_ANALYSIS_HH_ #define WRAP_BUNCH_TUNE_ANALYSIS_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh index 7f01e87d..c2e94d47 100644 --- a/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh +++ b/src/orbit/BunchDiagnostics/wrap_bunch_twiss_analysis.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BUNCH_TWISS_ANALYSIS_HH_ #define WRAP_BUNCH_TWISS_ANALYSIS_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Errors/wrap_errorbase.cc b/src/orbit/Errors/wrap_errorbase.cc index 82494511..186d5e8c 100644 --- a/src/orbit/Errors/wrap_errorbase.cc +++ b/src/orbit/Errors/wrap_errorbase.cc @@ -1,4 +1,4 @@ -#include "Python.h" +#include #include "orbit_mpi.hh" #include "pyORBIT_Object.hh" diff --git a/src/orbit/FieldTracker/wrap_fieldtracker.hh b/src/orbit/FieldTracker/wrap_fieldtracker.hh index c981ff1b..036086f4 100644 --- a/src/orbit/FieldTracker/wrap_fieldtracker.hh +++ b/src/orbit/FieldTracker/wrap_fieldtracker.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_FIELDTRACKER_HH_ #define WRAP_ORBIT_FIELDTRACKER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/Impedances/wrap_LImpedance.hh b/src/orbit/Impedances/wrap_LImpedance.hh index d2936333..5ffebd3d 100644 --- a/src/orbit/Impedances/wrap_LImpedance.hh +++ b/src/orbit/Impedances/wrap_LImpedance.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LIMPEDANCE_H #define WRAP_LIMPEDANCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/Impedances/wrap_TImpedance.hh b/src/orbit/Impedances/wrap_TImpedance.hh index d001bb24..ffca3037 100644 --- a/src/orbit/Impedances/wrap_TImpedance.hh +++ b/src/orbit/Impedances/wrap_TImpedance.hh @@ -1,7 +1,7 @@ #ifndef WRAP_TIMPEDANCE_H #define WRAP_TIMPEDANCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/Impedances/wrap_impedances.hh b/src/orbit/Impedances/wrap_impedances.hh index c6270c41..cef05bc4 100644 --- a/src/orbit/Impedances/wrap_impedances.hh +++ b/src/orbit/Impedances/wrap_impedances.hh @@ -1,7 +1,7 @@ #ifndef WRAP_IMPEDANCES_H #define WRAP_IMPEDANCES_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/MaterialInteractions/wrap_collimator.hh b/src/orbit/MaterialInteractions/wrap_collimator.hh index 278e7b70..5f3069a0 100644 --- a/src/orbit/MaterialInteractions/wrap_collimator.hh +++ b/src/orbit/MaterialInteractions/wrap_collimator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_COLLIMATOR_HH_ #define WRAP_ORBIT_COLLIMATOR_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/MaterialInteractions/wrap_foil.hh b/src/orbit/MaterialInteractions/wrap_foil.hh index eafb1808..7f9b35e7 100644 --- a/src/orbit/MaterialInteractions/wrap_foil.hh +++ b/src/orbit/MaterialInteractions/wrap_foil.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_FOIL_HH_ #define WRAP_ORBIT_FOIL_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc index 6f2c9d9d..7939b3b1 100644 --- a/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc +++ b/src/orbit/ParticlesAttributes/ParticleAttributesFactory.cc @@ -46,7 +46,7 @@ ParticleAttributes* ParticleAttributesFactory::getParticleAttributesInstance( int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ diff --git a/src/orbit/RFCavities/wrap_Barrier_Cav.hh b/src/orbit/RFCavities/wrap_Barrier_Cav.hh index ccb7d80d..13b6760f 100644 --- a/src/orbit/RFCavities/wrap_Barrier_Cav.hh +++ b/src/orbit/RFCavities/wrap_Barrier_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BARRIER_CAV_H #define WRAP_BARRIER_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh index d12449e6..5b6f969a 100644 --- a/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh +++ b/src/orbit/RFCavities/wrap_Dual_Harmonic_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_Dual_Harmonic_Cav_H #define WRAP_Dual_Harmonic_Cav_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Frequency_Cav.hh b/src/orbit/RFCavities/wrap_Frequency_Cav.hh index c2e8333d..e3311012 100644 --- a/src/orbit/RFCavities/wrap_Frequency_Cav.hh +++ b/src/orbit/RFCavities/wrap_Frequency_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_FREQUENCY_CAV_H #define WRAP_FREQUENCY_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_Harmonic_Cav.hh b/src/orbit/RFCavities/wrap_Harmonic_Cav.hh index 63710662..5b686371 100644 --- a/src/orbit/RFCavities/wrap_Harmonic_Cav.hh +++ b/src/orbit/RFCavities/wrap_Harmonic_Cav.hh @@ -1,7 +1,7 @@ #ifndef WRAP_HARMONIC_CAV_H #define WRAP_HARMONIC_CAV_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/RFCavities/wrap_rfcavities.hh b/src/orbit/RFCavities/wrap_rfcavities.hh index 1a327081..cecebb20 100644 --- a/src/orbit/RFCavities/wrap_rfcavities.hh +++ b/src/orbit/RFCavities/wrap_rfcavities.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RFCAVITIES_H #define WRAP_RFCAVITIES_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/orbit/SyncPart.cc b/src/orbit/SyncPart.cc index 6494ecbf..216fa23c 100644 --- a/src/orbit/SyncPart.cc +++ b/src/orbit/SyncPart.cc @@ -24,7 +24,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #include "SyncPart.hh" @@ -326,7 +326,7 @@ void SyncPart::readSyncPart(const char* fileName){ int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ @@ -469,7 +469,7 @@ void SyncPart::print(std::ostream& Out) int rank_MPI = 0; int size_MPI = 1; int iMPIini = 0; - MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local()->comm; + MPI_Comm MPI_COMM_Local = bunch->getMPI_Comm_Local(); ORBIT_MPI_Initialized(&iMPIini); if(iMPIini > 0){ diff --git a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc index 22021ae7..2bd4c3f7 100644 --- a/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc +++ b/src/orbit/SynchPartRedefinition/SynchPartRedefinitionZdE.cc @@ -70,14 +70,14 @@ void SynchPartRedefinitionZdE::analyzeBunch(Bunch* bunch){ } int count_MPI = 0; - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,bunch->getMPI_Comm_Local()); count = count_MPI; double total_macrosize_MPI = 0.; - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_MPI,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = total_macrosize_MPI; - ORBIT_MPI_Allreduce(z_dE_avg_arr,z_dE_avg_arr_MPI,2,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(z_dE_avg_arr,z_dE_avg_arr_MPI,2,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(fabs(total_macrosize) > 0.){ for(int i = 0; i < 2; i++){ diff --git a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh index ef7ace81..2df15fb3 100644 --- a/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh +++ b/src/orbit/SynchPartRedefinition/wrap_synch_part_redefinition_z_de.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SYNCH_PARTICLE_REDEFINITION_HH_ #define WRAP_SYNCH_PARTICLE_REDEFINITION_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/orbit/wrap_bunch.cc b/src/orbit/wrap_bunch.cc index 68824b4e..f6936041 100644 --- a/src/orbit/wrap_bunch.cc +++ b/src/orbit/wrap_bunch.cc @@ -9,6 +9,7 @@ // /////////////////////////////////////////////////////////////////////////// #include "wrap_bunch.hh" +#include "wrap_mpi_comm.hh" #include "wrap_syncpart.hh" #include "wrap_bunch_twiss_analysis.hh" #include "wrap_bunch_tune_analysis.hh" @@ -28,7 +29,7 @@ namespace wrap_orbit_bunch{ //constructor for python class wrapping Bunch instance //It never will be called directly - static PyObject* Bunch_new(PyTypeObject *type, PyObject *args, PyObject *kwds){ + static PyObject* Bunch_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) { pyORBIT_Object* self; self = (pyORBIT_Object *) type->tp_alloc(type, 0); self->cpp_obj = NULL; @@ -37,7 +38,7 @@ namespace wrap_orbit_bunch{ //initializator for python Bunch class //this is implementation of the __init__ method - static int Bunch_init(pyORBIT_Object *self, PyObject *args, PyObject *kwds){ + static int Bunch_init(pyORBIT_Object *self, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)){ //std::cerr<<"The Bunch __init__ has been called!"<cpp_obj = (void*) new Bunch(); @@ -62,7 +63,7 @@ namespace wrap_orbit_bunch{ //---------------------------------------------------------------- //returns the SyncPart python class wrapper instance - static PyObject* Bunch_getSyncParticle(PyObject *self, PyObject *args){ + static PyObject* Bunch_getSyncParticle(PyObject *self, PyObject *Py_UNUSED(ignored)){ Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; PyObject* pySyncPart = cpp_bunch->getSyncPart()->getPyWrapper(); Py_INCREF(pySyncPart); @@ -76,29 +77,34 @@ namespace wrap_orbit_bunch{ //---------------------------------------------------------------- //returns the local MPI Comm for this bunch - static PyObject* Bunch_getMPIComm(PyObject *self, PyObject *args){ + static PyObject* Bunch_getMPIComm(PyObject *self, PyObject *Py_UNUSED(ignored)) { Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; - PyObject* pyMPIComm = (PyObject*) cpp_bunch->getMPI_Comm_Local(); - Py_INCREF(pyMPIComm); - return pyMPIComm; + + PyObject* mpi_comm_type = wrap_orbit_mpi_comm::getMPI_CommType("MPI_Comm"); + PyObject* pyComm = PyObject_CallFunction(mpi_comm_type, NULL); + if (pyComm == NULL) { + return NULL; + } + + ((pyORBIT_MPI_Comm*)pyComm)->comm = cpp_bunch->getMPI_Comm_Local(); + + return pyComm; } - //sets a new local MPI Comm for this bunch - static PyObject* Bunch_setMPIComm(PyObject *self, PyObject *args){ - Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; - int nVars = PyTuple_Size(args); - PyObject* pyMPIComm; - if(nVars == 1){ - if(!PyArg_ParseTuple(args,"O:setMPIComm",&pyMPIComm)){ - error("The Bunch method setMPIComm(mpi_comm) - mpi_comm is needed."); - } - cpp_bunch->setMPI_Comm_Local( (pyORBIT_MPI_Comm*) pyMPIComm); - } - else{ - error("The Bunch method should be setMPIComm(mpi_comm)."); - } - Py_INCREF(Py_None); - return Py_None; + //sets a new local MPI Comm for this bunch + static PyObject* Bunch_setMPIComm(PyObject *self, PyObject *arg) { + Bunch* cpp_bunch = (Bunch*) ((pyORBIT_Object *) self)->cpp_obj; + + PyObject* mpi_comm_type = wrap_orbit_mpi_comm::getMPI_CommType("MPI_Comm"); + if (!PyObject_TypeCheck(arg, (PyTypeObject*)mpi_comm_type)) { + PyErr_SetString(PyExc_TypeError, "expected an MPI_Comm object"); + return NULL; + } + + pyORBIT_MPI_Comm *pyComm = (pyORBIT_MPI_Comm*)arg; + cpp_bunch->setMPI_Comm_Local(pyComm->comm); + + Py_RETURN_NONE; } //--------------------------------------------------------------- @@ -1175,9 +1181,9 @@ namespace wrap_orbit_bunch{ //-------------------------------------------------------- // class Bunch wrapper START //-------------------------------------------------------- - { "getMPIComm", Bunch_getMPIComm ,METH_VARARGS,"Returns MPI Comm of this bunch"}, - { "setMPIComm", Bunch_setMPIComm ,METH_VARARGS,"Sets a new MPI Comm for this bunch"}, - { "getSyncParticle", Bunch_getSyncParticle ,METH_VARARGS,"Returns syncParticle class instance"}, + { "getMPIComm", Bunch_getMPIComm ,METH_NOARGS,"Returns MPI Comm of this bunch"}, + { "setMPIComm", Bunch_setMPIComm ,METH_O,"Sets a new MPI Comm for this bunch"}, + { "getSyncParticle", Bunch_getSyncParticle ,METH_NOARGS,"Returns syncParticle class instance"}, { "addParticle", Bunch_addParticle ,METH_VARARGS,"Adds a macro-particle to the bunch"}, { "deleteParticle", Bunch_deleteParticle ,METH_VARARGS,"Removes macro-particle from the bunch and call compress inside"}, { "deleteParticleFast", Bunch_deleteParticleFast ,METH_VARARGS,"Removes macro-particle from the bunch very fast"}, @@ -1314,15 +1320,6 @@ extern "C" { return module; } - PyObject* getBunchType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.bunch"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - - #ifdef __cplusplus } #endif diff --git a/src/orbit/wrap_bunch.hh b/src/orbit/wrap_bunch.hh index f096625c..1157f294 100644 --- a/src/orbit/wrap_bunch.hh +++ b/src/orbit/wrap_bunch.hh @@ -16,7 +16,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #ifdef __cplusplus extern "C" { @@ -25,7 +25,7 @@ extern "C" { namespace wrap_orbit_bunch{ /* The name of the function was changed to avoid collision with PyImport magic naming */ PyMODINIT_FUNC initbunch(void); - PyObject* getBunchType(const char* name); + PyObject* getBunchType(const char* name); } #ifdef __cplusplus diff --git a/src/orbit/wrap_syncpart.hh b/src/orbit/wrap_syncpart.hh index 01770894..af1c37d6 100644 --- a/src/orbit/wrap_syncpart.hh +++ b/src/orbit/wrap_syncpart.hh @@ -11,7 +11,7 @@ // INCLUDE FILES // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/Grid1D.cc b/src/spacecharge/Grid1D.cc index 36caeb54..e3259e26 100644 --- a/src/spacecharge/Grid1D.cc +++ b/src/spacecharge/Grid1D.cc @@ -759,7 +759,7 @@ void Grid1D::getBinIndAndWZSmoothed(double z, } /** synchronizeMPI */ -void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) +void Grid1D::synchronizeMPI(MPI_Comm comm) { // ====== MPI start ======== @@ -776,7 +776,7 @@ void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) inArr[i] = arr_[i]; } - if(pyComm == NULL) + if(comm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr, outArr, size_MPI, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); @@ -784,7 +784,7 @@ void Grid1D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) else { ORBIT_MPI_Allreduce(inArr, outArr, size_MPI, - MPI_DOUBLE, MPI_SUM, pyComm->comm); + MPI_DOUBLE, MPI_SUM, comm); } for(int i = 0; i < zSize_; i++) diff --git a/src/spacecharge/Grid1D.hh b/src/spacecharge/Grid1D.hh index 18b292e5..2b096cd3 100644 --- a/src/spacecharge/Grid1D.hh +++ b/src/spacecharge/Grid1D.hh @@ -3,7 +3,6 @@ // MPI Function Wrappers #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" #include #include @@ -135,7 +134,7 @@ public: void calcGradientSmoothed(double z, double& ez); /** synchronizeMPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* comm); + void synchronizeMPI(MPI_Comm comm); private: diff --git a/src/spacecharge/Grid2D.cc b/src/spacecharge/Grid2D.cc index c3c324c1..78f9c399 100644 --- a/src/spacecharge/Grid2D.cc +++ b/src/spacecharge/Grid2D.cc @@ -440,7 +440,7 @@ int Grid2D::isInside(double x,double y){ } /**synchronizeMPI */ -void Grid2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ +void Grid2D::synchronizeMPI(MPI_Comm comm){ // ====== MPI start ======== int size_MPI = xSize_ * ySize_; int buff_index0 = 0; @@ -456,10 +456,10 @@ void Grid2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ } } - if(pyComm == NULL) { + if(comm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,comm); } count = 0; diff --git a/src/spacecharge/Grid2D.hh b/src/spacecharge/Grid2D.hh index 419be46d..30b0bdfe 100644 --- a/src/spacecharge/Grid2D.hh +++ b/src/spacecharge/Grid2D.hh @@ -5,7 +5,6 @@ //MPI Function Wrappers #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" #include #include @@ -93,7 +92,7 @@ public: int getSizeY(); /** synchronizeMPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* comm); + void synchronizeMPI(MPI_Comm comm); /** Returns 1 if (x,y) is inside the grid region, and 0 otherwise */ int isInside(double x,double y); diff --git a/src/spacecharge/Grid3D.cc b/src/spacecharge/Grid3D.cc index 401b34e2..84a95556 100644 --- a/src/spacecharge/Grid3D.cc +++ b/src/spacecharge/Grid3D.cc @@ -809,7 +809,7 @@ double Grid3D::calcSheetGradient(int iZ,int iX,int iY, } /**synchronize MPI */ -void Grid3D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ +void Grid3D::synchronizeMPI(MPI_Comm pyComm){ // ====== MPI start ======== int size_MPI = nX_ * nY_*nZ_; int buff_index0 = 0; @@ -827,10 +827,10 @@ void Grid3D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm){ } } - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,size_MPI,MPI_DOUBLE,MPI_SUM,pyComm); } count = 0; diff --git a/src/spacecharge/Grid3D.hh b/src/spacecharge/Grid3D.hh index fa15ebad..57d3fb2f 100644 --- a/src/spacecharge/Grid3D.hh +++ b/src/spacecharge/Grid3D.hh @@ -18,7 +18,6 @@ //MPI Function Wrappers #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" //ORBIT bunch #include "Bunch.hh" @@ -175,7 +174,7 @@ public: double getSliceSum(double z); /** synchronize MPI */ - void synchronizeMPI(pyORBIT_MPI_Comm* pyComm); + void synchronizeMPI(MPI_Comm pyComm); protected: //--------------------------------------- diff --git a/src/spacecharge/SpaceChargeCalcUnifEllipse.cc b/src/spacecharge/SpaceChargeCalcUnifEllipse.cc index 250ee81b..83af0bbc 100644 --- a/src/spacecharge/SpaceChargeCalcUnifEllipse.cc +++ b/src/spacecharge/SpaceChargeCalcUnifEllipse.cc @@ -143,7 +143,7 @@ void SpaceChargeCalcUnifEllipse::bunchAnalysis(Bunch* bunch){ } //calculates sum over all CPUs - ORBIT_MPI_Allreduce(coord_avg,coord_avg_out,7,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(coord_avg,coord_avg_out,7,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); total_macrosize = coord_avg_out[6]; if(total_macrosize == 0.){ @@ -233,7 +233,7 @@ void SpaceChargeCalcUnifEllipse::bunchAnalysis(Bunch* bunch){ } } //calculates sum over all CPUs - ORBIT_MPI_Allreduce(macroSizesEll_arr,macroSizesEll_MPI_arr,nEllipses,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(macroSizesEll_arr,macroSizesEll_MPI_arr,nEllipses,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); for(int ie = 0; ie < nEllipses; ie++){ macroSizesEll_arr[ie] = macroSizesEll_MPI_arr[ie]; //std::cout<<"debug 0 ie ="<< ie <<" macrosize="<< macroSizesEll_MPI_arr[ie] << std::endl; diff --git a/src/spacecharge/SpaceChargeCalcUnifEllipse.hh b/src/spacecharge/SpaceChargeCalcUnifEllipse.hh index d88f9ba3..246cb936 100644 --- a/src/spacecharge/SpaceChargeCalcUnifEllipse.hh +++ b/src/spacecharge/SpaceChargeCalcUnifEllipse.hh @@ -9,7 +9,6 @@ //MPI Function Wrappers #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" #include #include diff --git a/src/spacecharge/wrap_boundary2d.hh b/src/spacecharge/wrap_boundary2d.hh index 7a5c6904..1a7eaa0f 100644 --- a/src/spacecharge/wrap_boundary2d.hh +++ b/src/spacecharge/wrap_boundary2d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_BOUNDARY_2D_H #define WRAP_BOUNDARY_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_forcesolverfft2d.hh b/src/spacecharge/wrap_forcesolverfft2d.hh index 85d52b56..787251b9 100644 --- a/src/spacecharge/wrap_forcesolverfft2d.hh +++ b/src/spacecharge/wrap_forcesolverfft2d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_FORCE_SOLVER_FFT_2D_H #define WRAP_SPACE_CHARGE_FORCE_SOLVER_FFT_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_grid1D.cc b/src/spacecharge/wrap_grid1D.cc index a194ae7c..a83c5f81 100644 --- a/src/spacecharge/wrap_grid1D.cc +++ b/src/spacecharge/wrap_grid1D.cc @@ -445,7 +445,7 @@ static PyObject* Grid1D_synchronizeMPI(PyObject *self, PyObject *args) { ORBIT_MPI_Finalize("Grid1D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_Grid1D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid1D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; diff --git a/src/spacecharge/wrap_grid1D.hh b/src/spacecharge/wrap_grid1D.hh index e7ed0805..4b111d1c 100644 --- a/src/spacecharge/wrap_grid1D.hh +++ b/src/spacecharge/wrap_grid1D.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_GRID_1D_H #define WRAP_SPACE_CHARGE_GRID_1D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/spacecharge/wrap_grid2D.cc b/src/spacecharge/wrap_grid2D.cc index e1fb5f84..b85aaa42 100644 --- a/src/spacecharge/wrap_grid2D.cc +++ b/src/spacecharge/wrap_grid2D.cc @@ -4,6 +4,7 @@ #include "wrap_grid2D.hh" #include "wrap_spacecharge.hh" #include "wrap_bunch.hh" +#include "wrap_mpi_comm.hh" #include @@ -180,7 +181,7 @@ extern "C" { if((!PyObject_IsInstance(pyMPIComm,py_mpi_comm_type))){ ORBIT_MPI_Finalize("Grid2D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_Grid2D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid2D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; diff --git a/src/spacecharge/wrap_grid2D.hh b/src/spacecharge/wrap_grid2D.hh index 73501b59..1cc4f599 100644 --- a/src/spacecharge/wrap_grid2D.hh +++ b/src/spacecharge/wrap_grid2D.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_GRID_2D_H #define WRAP_SPACE_CHARGE_GRID_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_grid3D.cc b/src/spacecharge/wrap_grid3D.cc index 5dcc32b0..dc92eac5 100644 --- a/src/spacecharge/wrap_grid3D.cc +++ b/src/spacecharge/wrap_grid3D.cc @@ -4,6 +4,7 @@ #include "wrap_grid3D.hh" #include "wrap_spacecharge.hh" #include "wrap_bunch.hh" +#include "wrap_mpi_comm.hh" #include @@ -195,7 +196,7 @@ extern "C" { if((!PyObject_IsInstance(pyMPIComm,py_mpi_comm_type))){ ORBIT_MPI_Finalize("Grid3D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_Grid3D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_Grid3D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; diff --git a/src/spacecharge/wrap_grid3D.hh b/src/spacecharge/wrap_grid3D.hh index 4a465399..be407e32 100644 --- a/src/spacecharge/wrap_grid3D.hh +++ b/src/spacecharge/wrap_grid3D.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_GRID_3D_H #define WRAP_SPACE_CHARGE_GRID_3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_lspacechargecalc.hh b/src/spacecharge/wrap_lspacechargecalc.hh index 17963c15..6c55a07a 100644 --- a/src/spacecharge/wrap_lspacechargecalc.hh +++ b/src/spacecharge/wrap_lspacechargecalc.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_L_H #define WRAP_SPACE_CHARGE_CALC_L_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/spacecharge/wrap_poissonsolverfft2d.hh b/src/spacecharge/wrap_poissonsolverfft2d.hh index 383cda0f..1f31604a 100644 --- a/src/spacecharge/wrap_poissonsolverfft2d.hh +++ b/src/spacecharge/wrap_poissonsolverfft2d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_POISSON_SOLVER_FFT_2D_H #define WRAP_SPACE_CHARGE_POISSON_SOLVER_FFT_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_poissonsolverfft3d.hh b/src/spacecharge/wrap_poissonsolverfft3d.hh index 6bda120c..4f78628c 100644 --- a/src/spacecharge/wrap_poissonsolverfft3d.hh +++ b/src/spacecharge/wrap_poissonsolverfft3d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_POISSON_SOLVER_FFT_3D_H #define WRAP_SPACE_CHARGE_POISSON_SOLVER_FFT_3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacecharge.cc b/src/spacecharge/wrap_spacecharge.cc index ab8d9ed5..079c6b9c 100644 --- a/src/spacecharge/wrap_spacecharge.cc +++ b/src/spacecharge/wrap_spacecharge.cc @@ -52,14 +52,6 @@ extern "C" { return module; } - PyObject* getSpaceChargeType(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.spacecharge"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif diff --git a/src/spacecharge/wrap_spacecharge.hh b/src/spacecharge/wrap_spacecharge.hh index 12bddf42..1120c9f1 100644 --- a/src/spacecharge/wrap_spacecharge.hh +++ b/src/spacecharge/wrap_spacecharge.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_H #define WRAP_SPACE_CHARGE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc2p5d.hh b/src/spacecharge/wrap_spacechargecalc2p5d.hh index 9ca19c00..bac019d2 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d.hh +++ b/src/spacecharge/wrap_spacechargecalc2p5d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_2P5D_H #define WRAP_SPACE_CHARGE_CALC_2P5D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh b/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh index b2551e92..bbf671d5 100644 --- a/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh +++ b/src/spacecharge/wrap_spacechargecalc2p5d_rb.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_2P5D_RB_H #define WRAP_SPACE_CHARGE_CALC_2P5D_RB_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc3d.hh b/src/spacecharge/wrap_spacechargecalc3d.hh index ec48fc43..61af06ff 100644 --- a/src/spacecharge/wrap_spacechargecalc3d.hh +++ b/src/spacecharge/wrap_spacechargecalc3d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_3D_H #define WRAP_SPACE_CHARGE_CALC_3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh index 6a8fb982..812733b5 100755 --- a/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh +++ b/src/spacecharge/wrap_spacechargecalc_slicebyslice_2D.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_SLICE_BY_SLICE_2D_H #define WRAP_SPACE_CHARGE_CALC_SLICE_BY_SLICE_2D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh index 85cc0fd9..fd9acf06 100644 --- a/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh +++ b/src/spacecharge/wrap_spacechargecalc_uniform_ellipse.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_CALC_UNIFORM_ELLIPSE_H #define WRAP_SPACE_CHARGE_CALC_UNIFORM_ELLIPSE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh b/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh index eb91c908..f483312c 100644 --- a/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh +++ b/src/spacecharge/wrap_spacechargeforcecalc2p5d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_SPACE_CHARGE_FORCE_CALC_2P5D_H #define WRAP_SPACE_CHARGE_FORCE_CALC_2P5D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh index 680a1c4f..a3e783d2 100644 --- a/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh +++ b/src/spacecharge/wrap_uniform_ellipsoid_field_calculator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UNIFORM_ELLIPSOID_FIELD_CALC_H #define WRAP_UNIFORM_ELLIPSOID_FIELD_CALC_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/teapot/wrap_matrix_generator.hh b/src/teapot/wrap_matrix_generator.hh index 9c9eaab2..0bf9bb8a 100644 --- a/src/teapot/wrap_matrix_generator.hh +++ b/src/teapot/wrap_matrix_generator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MATRIX_GENERATOR_H #define WRAP_MATRIX_GENERATOR_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" diff --git a/src/teapot/wrap_teapotbase.cc b/src/teapot/wrap_teapotbase.cc index da405a16..68525d9a 100644 --- a/src/teapot/wrap_teapotbase.cc +++ b/src/teapot/wrap_teapotbase.cc @@ -1,4 +1,4 @@ -#include "Python.h" +#include #include "orbit_mpi.hh" #include "pyORBIT_Object.hh" diff --git a/src/trackerrk4/ExtEffectsContainer.hh b/src/trackerrk4/ExtEffectsContainer.hh index 321ba9db..73994f9b 100644 --- a/src/trackerrk4/ExtEffectsContainer.hh +++ b/src/trackerrk4/ExtEffectsContainer.hh @@ -3,7 +3,7 @@ -#include "Python.h" +#include #include "ExternalEffects.hh" #include diff --git a/src/trackerrk4/PyExternalEffects.hh b/src/trackerrk4/PyExternalEffects.hh index 9c100b95..f5ecce14 100644 --- a/src/trackerrk4/PyExternalEffects.hh +++ b/src/trackerrk4/PyExternalEffects.hh @@ -29,7 +29,7 @@ #ifndef PY_EXTERNAL_EFFECTS_H #define PY_EXTERNAL_EFFECTS_H -#include "Python.h" +#include #include "ExternalEffects.hh" diff --git a/src/trackerrk4/wrap_ext_effects_container.hh b/src/trackerrk4/wrap_ext_effects_container.hh index d0a532c6..0ab910a7 100644 --- a/src/trackerrk4/wrap_ext_effects_container.hh +++ b/src/trackerrk4/wrap_ext_effects_container.hh @@ -1,7 +1,7 @@ #ifndef WRAP_EXT_EFFECTS_CONTAINER_HH_ #define WRAP_EXT_EFFECTS_CONTAINER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_py_external_effects.hh b/src/trackerrk4/wrap_py_external_effects.hh index ec7dc15a..88beeff6 100644 --- a/src/trackerrk4/wrap_py_external_effects.hh +++ b/src/trackerrk4/wrap_py_external_effects.hh @@ -1,7 +1,7 @@ #ifndef WRAP_PY_EXTERNAL_EFFECTS_H #define WRAP_PY_EXTERNAL_EFFECTS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_runge_kutta_tracker.hh b/src/trackerrk4/wrap_runge_kutta_tracker.hh index c8bce3f1..b25398be 100644 --- a/src/trackerrk4/wrap_runge_kutta_tracker.hh +++ b/src/trackerrk4/wrap_runge_kutta_tracker.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RUNGE_KUTTA_TRACKER_H #define WRAP_RUNGE_KUTTA_TRACKER_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/trackerrk4/wrap_trackerrk4.cc b/src/trackerrk4/wrap_trackerrk4.cc index 5d23b55c..a955b7be 100644 --- a/src/trackerrk4/wrap_trackerrk4.cc +++ b/src/trackerrk4/wrap_trackerrk4.cc @@ -29,14 +29,6 @@ extern "C" { return module; } - PyObject* getTrackerRK4Type(const char* name){ - PyObject* mod = PyImport_ImportModule("orbit.core.trackerrk4"); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - #ifdef __cplusplus } #endif diff --git a/src/trackerrk4/wrap_trackerrk4.hh b/src/trackerrk4/wrap_trackerrk4.hh index dcbf5693..59bf3177 100644 --- a/src/trackerrk4/wrap_trackerrk4.hh +++ b/src/trackerrk4/wrap_trackerrk4.hh @@ -1,7 +1,7 @@ #ifndef WRAP_RK4_TRACKER_H #define WRAP_RK4_TRACKER_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/CppPyWrapper.hh b/src/utils/CppPyWrapper.hh index ada658e6..c43fa22e 100644 --- a/src/utils/CppPyWrapper.hh +++ b/src/utils/CppPyWrapper.hh @@ -15,7 +15,7 @@ #ifndef CPP_PY_WRAPPER_H #define CPP_PY_WRAPPER_H -#include "Python.h" +#include namespace OrbitUtils{ diff --git a/src/utils/FieldSourceContainer.hh b/src/utils/FieldSourceContainer.hh index ce8c4c01..bfd4c06d 100644 --- a/src/utils/FieldSourceContainer.hh +++ b/src/utils/FieldSourceContainer.hh @@ -18,7 +18,7 @@ #ifndef FIELDSOURCECONTAINER_HH_ #define FIELDSOURCECONTAINER_HH_ -#include "Python.h" +#include #include "BaseFieldSource.hh" #include diff --git a/src/utils/PyBaseFieldSource.hh b/src/utils/PyBaseFieldSource.hh index f00cee04..a79ce1dd 100644 --- a/src/utils/PyBaseFieldSource.hh +++ b/src/utils/PyBaseFieldSource.hh @@ -22,7 +22,7 @@ #ifndef PY_BASE_FIELD_SOURCE_H #define PY_BASE_FIELD_SOURCE_H -#include "Python.h" +#include #include "BaseFieldSource.hh" diff --git a/src/utils/bunch/BunchExtremaCalculator.cc b/src/utils/bunch/BunchExtremaCalculator.cc index 03057d2c..0571fcdb 100644 --- a/src/utils/bunch/BunchExtremaCalculator.cc +++ b/src/utils/bunch/BunchExtremaCalculator.cc @@ -65,7 +65,7 @@ void BunchExtremaCalculator::getExtremaXYZ(Bunch* bunch, gridLimArr[2] = - gridLimArr[2]; gridLimArr[4] = - gridLimArr[4]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; gridLimArr_out[2] = - gridLimArr_out[2]; @@ -114,7 +114,7 @@ void BunchExtremaCalculator::getExtremaXpYpdE(Bunch* bunch, gridLimArr[2] = - gridLimArr[2]; gridLimArr[4] = - gridLimArr[4]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,6,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; gridLimArr_out[2] = - gridLimArr_out[2]; @@ -152,7 +152,7 @@ void BunchExtremaCalculator::getExtremaZ(Bunch* bunch, gridLimArr[0] = - gridLimArr[0]; - ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,2,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(gridLimArr,gridLimArr_out,2,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); gridLimArr_out[0] = - gridLimArr_out[0]; @@ -182,8 +182,8 @@ void BunchExtremaCalculator::getExtremaR(Bunch* bunch, double& rMax) double x_avg_global = 0.; double y_avg_global = 0.; - ORBIT_MPI_Allreduce(&x_avg,&x_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(&y_avg,&y_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&x_avg,&x_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(&y_avg,&y_avg_global,1,MPI_DOUBLE,MPI_SUM,bunch->getMPI_Comm_Local()); if(nParts > 0){ x_avg = x_avg_global/nParts; @@ -203,7 +203,7 @@ void BunchExtremaCalculator::getExtremaR(Bunch* bunch, double& rMax) if(rMax > rMax_local) rMax_local = rMax; } - ORBIT_MPI_Allreduce(&rMax_local,&rMax_global,1,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&rMax_local,&rMax_global,1,MPI_DOUBLE,MPI_MAX,bunch->getMPI_Comm_Local()); rMax = rMax_global; } diff --git a/src/utils/bunch/InitialCoordsAttrFunctions.cc b/src/utils/bunch/InitialCoordsAttrFunctions.cc index 2ba87291..63a7562b 100644 --- a/src/utils/bunch/InitialCoordsAttrFunctions.cc +++ b/src/utils/bunch/InitialCoordsAttrFunctions.cc @@ -113,8 +113,8 @@ namespace OrbitUtils{ int transport_mtrx_from_init_coords(Bunch* bunch, Matrix* A_mtr, int appl_twiss_x, int appl_twiss_y, int appl_twiss_z){ int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local(), &rank_MPI); if(bunch->hasParticleAttributes("ParticleInitialCoordinates") == 0){ if(rank_MPI == 0){ @@ -190,9 +190,9 @@ namespace OrbitUtils{ } } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg,arr_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_init_avg,arr_init_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg,arr_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_init_avg,arr_init_avg_mpi,6,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); total_macrosize = total_macrosize_mpi; @@ -249,7 +249,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ @@ -265,7 +265,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ diff --git a/src/utils/bunch/ParticlesWithIdFunctions.cc b/src/utils/bunch/ParticlesWithIdFunctions.cc index 059f641e..35f301b6 100644 --- a/src/utils/bunch/ParticlesWithIdFunctions.cc +++ b/src/utils/bunch/ParticlesWithIdFunctions.cc @@ -51,8 +51,8 @@ namespace OrbitUtils{ int n_parts = bunch->getSize(); if(n_parts == 0) return; int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch->getMPI_Comm_Local(), &rank_MPI); if(bunch->hasParticleAttributes("ParticleIdNumber") == 0){ if(rank_MPI == 0){ std::cerr << "OrbitUtils::bunch_utils_functions::bunch_sort_id(Bunch* bunch) function"<< std::endl; @@ -99,8 +99,8 @@ namespace OrbitUtils{ */ int transport_mtrx(Bunch* bunch_in, Bunch* bunch_out, Matrix* A_mtr, int appl_twiss_x, int appl_twiss_y, int appl_twiss_z){ int size_MPI,rank_MPI; - ORBIT_MPI_Comm_size(bunch_in->getMPI_Comm_Local()->comm, &size_MPI); - ORBIT_MPI_Comm_rank(bunch_in->getMPI_Comm_Local()->comm, &rank_MPI); + ORBIT_MPI_Comm_size(bunch_in->getMPI_Comm_Local(), &size_MPI); + ORBIT_MPI_Comm_rank(bunch_in->getMPI_Comm_Local(), &rank_MPI); if(bunch_in->hasParticleAttributes("ParticleIdNumber") == 0 || bunch_out->hasParticleAttributes("ParticleIdNumber") == 0){ if(rank_MPI == 0){ std::cerr << "OrbitUtils::bunch_utils_functions::transport_mtrx(...) function"<< std::endl; @@ -218,9 +218,9 @@ namespace OrbitUtils{ } } - ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg_in,arr_avg_in_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); - ORBIT_MPI_Allreduce(arr_avg_out,arr_avg_out_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(&total_macrosize,&total_macrosize_mpi,1,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg_in,arr_avg_in_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); + ORBIT_MPI_Allreduce(arr_avg_out,arr_avg_out_mpi,6,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); total_macrosize = total_macrosize_mpi; @@ -276,7 +276,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ @@ -292,7 +292,7 @@ namespace OrbitUtils{ count++; } } - ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()->comm); + ORBIT_MPI_Allreduce(mtrx_arr,mtrx_arr_mpi,36,MPI_DOUBLE,MPI_SUM,b_in_tmp->getMPI_Comm_Local()); count = 0; for (int i = 0; i < 6; i++){ for (int j = 0; j < 6; j++){ diff --git a/src/utils/bunch/wrap_bunch_extrema_calculator.hh b/src/utils/bunch/wrap_bunch_extrema_calculator.hh index fcd41ae3..3358057a 100644 --- a/src/utils/bunch/wrap_bunch_extrema_calculator.hh +++ b/src/utils/bunch/wrap_bunch_extrema_calculator.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_BUNCH_H #define WRAP_UTILS_BUNCH_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/bunch/wrap_bunch_utils_functions.hh b/src/utils/bunch/wrap_bunch_utils_functions.hh index 2eeb0f3d..b4cf027f 100644 --- a/src/utils/bunch/wrap_bunch_utils_functions.hh +++ b/src/utils/bunch/wrap_bunch_utils_functions.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_BUNCH_FUNCTIONS_H #define WRAP_UTILS_BUNCH_FUNCTIONS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/ShiftedFieldSource.cc b/src/utils/field_sources/ShiftedFieldSource.cc index 3fe1bb80..fd357bbb 100644 --- a/src/utils/field_sources/ShiftedFieldSource.cc +++ b/src/utils/field_sources/ShiftedFieldSource.cc @@ -23,7 +23,7 @@ // the external coordinate system by coordTransformBack (3x3) matrix. // /////////////////////////////////////////////////////////////////////////// -#include "Python.h" +#include #include "orbit_mpi.hh" diff --git a/src/utils/field_sources/wrap_dipole_field_source.hh b/src/utils/field_sources/wrap_dipole_field_source.hh index b7050bb5..b39db8d6 100644 --- a/src/utils/field_sources/wrap_dipole_field_source.hh +++ b/src/utils/field_sources/wrap_dipole_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_DIPOLE_FIELD_SOURCE_H #define WRAP_DIPOLE_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_field_sources_module.hh b/src/utils/field_sources/wrap_field_sources_module.hh index 008d89c0..e56441c3 100644 --- a/src/utils/field_sources/wrap_field_sources_module.hh +++ b/src/utils/field_sources/wrap_field_sources_module.hh @@ -1,7 +1,7 @@ #ifndef WRAP_FIELD_SOURCES_MODULE_H #define WRAP_FIELD_SOURCES_MODULE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_loop_field_source.hh b/src/utils/field_sources/wrap_loop_field_source.hh index d09e8485..39f96d4b 100644 --- a/src/utils/field_sources/wrap_loop_field_source.hh +++ b/src/utils/field_sources/wrap_loop_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_LOOP_FIELD_SOURCE_H #define WRAP_LOOP_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh index c29b0f54..ccf97665 100644 --- a/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh +++ b/src/utils/field_sources/wrap_magnetic_field_source_grid3d.hh @@ -1,7 +1,7 @@ #ifndef WRAP_MAGNET_FIELD_SOURCE_GRID3D_H #define WRAP_MAGNET_FIELD_SOURCE_GRID3D_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/field_sources/wrap_quad_field_source.hh b/src/utils/field_sources/wrap_quad_field_source.hh index 5d91fff8..d83fc376 100644 --- a/src/utils/field_sources/wrap_quad_field_source.hh +++ b/src/utils/field_sources/wrap_quad_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_QUAD_FIELD_SOURCE_H #define WRAP_QUAD_FIELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/harmonic_analysis/wrap_harmonic_data.hh b/src/utils/harmonic_analysis/wrap_harmonic_data.hh index 4b0e5ada..b38609d1 100644 --- a/src/utils/harmonic_analysis/wrap_harmonic_data.hh +++ b/src/utils/harmonic_analysis/wrap_harmonic_data.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_HARMONIC_DATA_HH_ #define WRAP_ORBIT_UTILS_HARMONIC_DATA_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/integration/wrap_gauss_legendre_integrator.hh b/src/utils/integration/wrap_gauss_legendre_integrator.hh index d3452f87..258a5d7a 100644 --- a/src/utils/integration/wrap_gauss_legendre_integrator.hh +++ b/src/utils/integration/wrap_gauss_legendre_integrator.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_GAUSS_LEGENDRE_INTEGRATOR_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/matrix/wrap_matrix.hh b/src/utils/matrix/wrap_matrix.hh index c2aa7570..3fca2cef 100644 --- a/src/utils/matrix/wrap_matrix.hh +++ b/src/utils/matrix/wrap_matrix.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_MATRIX_H #define WRAP_UTILS_MATRIX_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/matrix/wrap_phase_vector.hh b/src/utils/matrix/wrap_phase_vector.hh index 33b04fdd..27f44540 100644 --- a/src/utils/matrix/wrap_phase_vector.hh +++ b/src/utils/matrix/wrap_phase_vector.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_PHASE_VECTOR_H #define WRAP_UTILS_PHASE_VECTOR_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/polynomial/wrap_polynomial.hh b/src/utils/polynomial/wrap_polynomial.hh index c3e4adc3..49086229 100644 --- a/src/utils/polynomial/wrap_polynomial.hh +++ b/src/utils/polynomial/wrap_polynomial.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_POLYNOMIAL_HH_ #define WRAP_ORBIT_UTILS_POLYNOMIAL_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/statistics/StatMoments2D.cc b/src/utils/statistics/StatMoments2D.cc index 3656b76a..58292b50 100644 --- a/src/utils/statistics/StatMoments2D.cc +++ b/src/utils/statistics/StatMoments2D.cc @@ -167,7 +167,7 @@ int StatMoments2D::getCount() } /** It will synchronize the moments through the MPI communicator */ -void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) +void StatMoments2D::synchronizeMPI(MPI_Comm pyComm) { int mpi_size = (max_order+1)*(max_order+1); int buff_index0 = -1; @@ -183,10 +183,10 @@ void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) } } - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(inArr,outArr,mpi_size,MPI_DOUBLE,MPI_SUM,pyComm); } ii = 0; @@ -198,10 +198,10 @@ void StatMoments2D::synchronizeMPI(pyORBIT_MPI_Comm* pyComm) } int count_MPI = -1; - if(pyComm == NULL) { + if(pyComm == MPI_COMM_NULL) { ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); } else { - ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,pyComm->comm); + ORBIT_MPI_Allreduce(&count,&count_MPI,1,MPI_INT,MPI_SUM,pyComm); } count = count_MPI; diff --git a/src/utils/statistics/StatMoments2D.hh b/src/utils/statistics/StatMoments2D.hh index 79ac3161..2f312ba0 100644 --- a/src/utils/statistics/StatMoments2D.hh +++ b/src/utils/statistics/StatMoments2D.hh @@ -2,7 +2,6 @@ #define STAT_MOMENTS_2D_H #include "orbit_mpi.hh" -#include "wrap_mpi_comm.hh" //pyORBIT utils #include "CppPyWrapper.hh" @@ -66,7 +65,7 @@ namespace OrbitUtils{ int getCount(); /** It will synchronize the moments through the MPI communicator */ - void synchronizeMPI(pyORBIT_MPI_Comm* pyComm); + void synchronizeMPI(MPI_Comm pyComm); /** Returns the emittance */ double getEmittance(); diff --git a/src/utils/statistics/wrap_statmoments2d.cc b/src/utils/statistics/wrap_statmoments2d.cc index d61a782d..539ac0da 100644 --- a/src/utils/statistics/wrap_statmoments2d.cc +++ b/src/utils/statistics/wrap_statmoments2d.cc @@ -172,7 +172,7 @@ extern "C" { if((!PyObject_IsInstance(pyMPIComm,py_mpi_comm_type))){ error("StatMoments2D.synchronizeMPI(MPI_Comm) - input parameter is not MPI_Comm"); } - cpp_StatMoments2D->synchronizeMPI((pyORBIT_MPI_Comm*) pyMPIComm); + cpp_StatMoments2D->synchronizeMPI(((pyORBIT_MPI_Comm*) pyMPIComm)->comm); } Py_INCREF(Py_None); return Py_None; diff --git a/src/utils/statistics/wrap_statmoments2d.hh b/src/utils/statistics/wrap_statmoments2d.hh index 3696dd37..1da57091 100644 --- a/src/utils/statistics/wrap_statmoments2d.hh +++ b/src/utils/statistics/wrap_statmoments2d.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_STAT_MOMENTS_2D_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_field_source_container.hh b/src/utils/wrap_field_source_container.hh index bb97c187..e7d37304 100644 --- a/src/utils/wrap_field_source_container.hh +++ b/src/utils/wrap_field_source_container.hh @@ -2,7 +2,7 @@ #define WRAP_FIELD_SOURCE_CONTAINER_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_function.hh b/src/utils/wrap_function.hh index 7d22dd4f..15c8ed5a 100644 --- a/src/utils/wrap_function.hh +++ b/src/utils/wrap_function.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_FUNCTION_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_numrecipes.hh b/src/utils/wrap_numrecipes.hh index f338562a..5ee49b3a 100644 --- a/src/utils/wrap_numrecipes.hh +++ b/src/utils/wrap_numrecipes.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_NUMRECIPES_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_py_base_field_source.hh b/src/utils/wrap_py_base_field_source.hh index b0d17767..330ac517 100644 --- a/src/utils/wrap_py_base_field_source.hh +++ b/src/utils/wrap_py_base_field_source.hh @@ -1,7 +1,7 @@ #ifndef WRAP_UTILS_PY_BASE_FILELD_SOURCE_H #define WRAP_UTILS_PY_BASE_FILELD_SOURCE_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_random.hh b/src/utils/wrap_random.hh index 3e7f14f6..abee30de 100644 --- a/src/utils/wrap_random.hh +++ b/src/utils/wrap_random.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_RANDOM_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_splinech.hh b/src/utils/wrap_splinech.hh index e9289340..97e14cab 100644 --- a/src/utils/wrap_splinech.hh +++ b/src/utils/wrap_splinech.hh @@ -2,7 +2,7 @@ #define WRAP_ORBIT_UTILS_SPLINE_CH_HH_ -#include "Python.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/utils/wrap_utils.cc b/src/utils/wrap_utils.cc index 820976a1..434880d7 100644 --- a/src/utils/wrap_utils.cc +++ b/src/utils/wrap_utils.cc @@ -58,15 +58,6 @@ extern "C" { return module; } - PyObject* getOrbitUtilsType(const char* name){ - PyObject* mod = PyImport_ImportModule(const_cast("orbit.core.orbit_utils")); - PyObject* pyType = PyObject_GetAttrString(mod,name); - Py_DECREF(mod); - Py_DECREF(pyType); - return pyType; - } - - #ifdef __cplusplus } #endif diff --git a/src/utils/wrap_utils.hh b/src/utils/wrap_utils.hh index 291799a4..04ed7fc7 100644 --- a/src/utils/wrap_utils.hh +++ b/src/utils/wrap_utils.hh @@ -1,7 +1,7 @@ #ifndef WRAP_ORBIT_UTILS_H #define WRAP_ORBIT_UTILS_H -#include "Python.h" +#include #ifdef __cplusplus extern "C" { From 86cdfa13afdeda52748a0adfe5bed89fa031b325 Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Fri, 19 Jun 2026 11:14:55 -0400 Subject: [PATCH 5/6] Restore comments and deleted header that I thought wasn't necessary. Switch to #include <...> in parity with Python.h --- src/main/pyORBIT_Object.hh | 2 +- src/mpi/wrap_mpi_comm.cc | 117 ++++++++++++++++++++++++----------- src/mpi/wrap_mpi_datatype.cc | 2 +- src/mpi/wrap_mpi_group.cc | 2 +- src/mpi/wrap_mpi_op.cc | 2 +- src/mpi/wrap_mpi_request.cc | 2 +- src/mpi/wrap_mpi_status.cc | 2 +- 7 files changed, 86 insertions(+), 43 deletions(-) diff --git a/src/main/pyORBIT_Object.hh b/src/main/pyORBIT_Object.hh index 7a037e54..80dbc41f 100644 --- a/src/main/pyORBIT_Object.hh +++ b/src/main/pyORBIT_Object.hh @@ -17,7 +17,7 @@ #ifndef PY_ORBIT_OBJECT_H #define PY_ORBIT_OBJECT_H -#include "structmember.h" +#include #ifdef __cplusplus extern "C" { diff --git a/src/mpi/wrap_mpi_comm.cc b/src/mpi/wrap_mpi_comm.cc index ca27414c..6c5c976e 100644 --- a/src/mpi/wrap_mpi_comm.cc +++ b/src/mpi/wrap_mpi_comm.cc @@ -1,4 +1,13 @@ +/////////////////////////////////////////////////////////////////////////// +// +// INCLUDE FILES +// +/////////////////////////////////////////////////////////////////////////// #include "orbit_mpi.hh" + +//this header is from Python package +#include + #include "wrap_mpi_comm.hh" namespace wrap_orbit_mpi_comm{ @@ -9,6 +18,12 @@ namespace wrap_orbit_mpi_comm{ extern "C" { #endif + //--------------------------------------------------------- + //Python MPI_Comm class definition + //--------------------------------------------------------- + + //constructor for python class wrapping MPI_Comm instance + //It never will be called directly static PyObject* mpi_comm_new(PyTypeObject *type, PyObject *Py_UNUSED(args), PyObject *Py_UNUSED(kwds)) { pyORBIT_MPI_Comm* self; @@ -17,6 +32,8 @@ extern "C" { return (PyObject *) self; } + //initializator for python MPI_Comm class + //this is implementation of the __init__ method static int mpi_comm_init(pyORBIT_MPI_Comm *Py_UNUSED(self), PyObject *args, PyObject *Py_UNUSED(kwds)){ if(PyTuple_Size(args) != 0){ error("MPI_Comm constructor cannot have an input parameter."); @@ -24,6 +41,7 @@ extern "C" { return 0; } + //feeing the mpi comm in the python MPI_Comm class static PyObject* mpi_comm_free(PyObject *self, PyObject *Py_UNUSED(ignored)){ pyORBIT_MPI_Comm* pyMPI_Comm = (pyORBIT_MPI_Comm*) self; if(pyMPI_Comm->comm != MPI_COMM_WORLD && pyMPI_Comm->comm != MPI_COMM_SELF){ @@ -34,7 +52,12 @@ extern "C" { return Py_None; } + //----------------------------------------------------- + //destructor for python MPI_Comm class. + //----------------------------------------------------- + //this is implementation of the __del__ method static void mpi_comm_del(pyORBIT_MPI_Comm* self){ + //std::cerr<<"The MPI_Comm __del__ has been called!"<comm; if(comm != MPI_COMM_NULL && comm != MPI_COMM_WORLD && comm != MPI_COMM_SELF){ ORBIT_MPI_Comm_free(&comm); @@ -42,58 +65,68 @@ extern "C" { self->ob_base.ob_type->tp_free((PyObject*)self); } + // defenition of the methods of the python MPI_Comm wrapper class + // they will be vailable from python level static PyMethodDef MPI_CommClassMethods[] = { { "free", mpi_comm_free ,METH_NOARGS,"Free MPI communicator."}, {NULL} }; + // defenition of the memebers of the python MPI_Comm wrapper class + // they will be vailable from python level static PyMemberDef MPI_CommClassMembers[] = { {NULL} }; + //new python MPI_Comm wrapper type definition PyTypeObject pyORBIT_MPI_Comm_Type = { PyVarObject_HEAD_INIT(NULL, 0) - "MPI_Comm", - sizeof(pyORBIT_MPI_Comm), - 0, - (destructor) mpi_comm_del, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - "The MPI_Comm python wrapper", - 0, - 0, - 0, - 0, - 0, - 0, - MPI_CommClassMethods, - MPI_CommClassMembers, - 0, - 0, - 0, - 0, - 0, - 0, - (initproc) mpi_comm_init, - 0, - mpi_comm_new, + "MPI_Comm", /*tp_name*/ + sizeof(pyORBIT_MPI_Comm), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + (destructor) mpi_comm_del, /*tp_dealloc*/ + 0, /*tp_print*/ + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash */ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ + "The MPI_Comm python wrapper", /* tp_doc */ + 0, /* tp_traverse */ + 0, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + MPI_CommClassMethods, /* tp_methods */ + MPI_CommClassMembers, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc) mpi_comm_init, /* tp_init */ + 0, /* tp_alloc */ + mpi_comm_new, /* tp_new */ }; + //-------------------------------------------------- + //Initialization function of the MPI_Comm class + //It will be called from orbit_mpi wrapper initialization + //-------------------------------------------------- void init_orbit_mpi_comm(PyObject* module){ if (PyType_Ready(&pyORBIT_MPI_Comm_Type) < 0) return; + //we put Py_INCREF(...) because PyModule_AddObject() steal the reference Py_INCREF(&pyORBIT_MPI_Comm_Type); PyObject * comm_module = PyModule_New("mpi_comm"); @@ -119,6 +152,9 @@ extern "C" { PyModule_AddObject(module, "mpi_comm", comm_module); } + //----------------------------------------------------------- + //The function that will be exposed as C/C++ API for MPI_Comm + //----------------------------------------------------------- pyORBIT_MPI_Comm* newMPI_Comm(){ pyORBIT_MPI_Comm* pyMPI_Comm = PyObject_New(pyORBIT_MPI_Comm,&pyORBIT_MPI_Comm_Type); pyMPI_Comm->comm = MPI_COMM_WORLD; @@ -134,4 +170,11 @@ extern "C" { } #endif +//end of namespace wrap_orbit_mpi_comm } + +/////////////////////////////////////////////////////////////////////////// +// +// END OF FILE +// +/////////////////////////////////////////////////////////////////////////// diff --git a/src/mpi/wrap_mpi_datatype.cc b/src/mpi/wrap_mpi_datatype.cc index 12ab0442..868b2b7a 100644 --- a/src/mpi/wrap_mpi_datatype.cc +++ b/src/mpi/wrap_mpi_datatype.cc @@ -6,7 +6,7 @@ #include "orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include diff --git a/src/mpi/wrap_mpi_group.cc b/src/mpi/wrap_mpi_group.cc index 2aad7957..c428a57a 100644 --- a/src/mpi/wrap_mpi_group.cc +++ b/src/mpi/wrap_mpi_group.cc @@ -6,7 +6,7 @@ #include "orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include diff --git a/src/mpi/wrap_mpi_op.cc b/src/mpi/wrap_mpi_op.cc index 3d73c313..ae6afa8d 100644 --- a/src/mpi/wrap_mpi_op.cc +++ b/src/mpi/wrap_mpi_op.cc @@ -6,7 +6,7 @@ #include "orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include diff --git a/src/mpi/wrap_mpi_request.cc b/src/mpi/wrap_mpi_request.cc index 73c6fad9..438dc9f8 100644 --- a/src/mpi/wrap_mpi_request.cc +++ b/src/mpi/wrap_mpi_request.cc @@ -6,7 +6,7 @@ #include "orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include diff --git a/src/mpi/wrap_mpi_status.cc b/src/mpi/wrap_mpi_status.cc index 81ad503c..7d97d565 100644 --- a/src/mpi/wrap_mpi_status.cc +++ b/src/mpi/wrap_mpi_status.cc @@ -6,7 +6,7 @@ #include "orbit_mpi.hh" //this header is from Python package -#include "structmember.h" +#include //c++ header for cerr and cout #include From ab98a875d0b9421165edbaee3b507c3a2a2a269d Mon Sep 17 00:00:00 2001 From: "Wood, Tony" Date: Fri, 19 Jun 2026 11:22:34 -0400 Subject: [PATCH 6/6] attempt to fix linking on linux --- src/meson.build | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/meson.build b/src/meson.build index e03091ac..46ed49be 100644 --- a/src/meson.build +++ b/src/meson.build @@ -8,7 +8,6 @@ endif dependencies = [] -dependencies += python.dependency() dependencies += dependency('fftw3', version: '>= 3.0.0', required: true) py_link_args = [] @@ -17,7 +16,10 @@ if host_machine.system() == 'darwin' # The unresolved symbols will be resolved once the Python interpreter loads libpyorbit. # The linker on MacOS is a bit more strict, so we need to explicitly tell it that # symbols from libpython will be nont resolvable for now. + dependencies += python.dependency() py_link_args += ['-Wl,-undefined,dynamic_lookup'] +else + dependencies += python.dependency(embed : true) endif # Detecting if MPICH or OPENMPI are installed and enabling support if present