diff --git a/src/cmfd_execute.F90 b/src/cmfd_execute.F90 index e49038482c..e8eb35f0e9 100644 --- a/src/cmfd_execute.F90 +++ b/src/cmfd_execute.F90 @@ -31,19 +31,19 @@ contains integer :: ierr ! petsc error code + ! set how many processors to run cmfd on + n_procs_cmfd = min(n_procs_cmfd,n_procs) + ! initialize mpi communicator - call petsc_init_mpi() + if(current_batch == n_inactive + 1) call petsc_init_mpi() ! filter procs - if (rank < 1) then + if (rank < n_procs_cmfd) then ! initialize slepc/petsc (communicates to world) if(current_batch == n_inactive + 1) call SlepcInitialize & & (PETSC_NULL_CHARACTER,ierr) - ! set global variable for number of procs in cmfd calc - call MPI_COMM_SIZE(PETSC_COMM_WORLD,n_procs_cmfd,ierr) - ! only run if master process if (master) then @@ -140,77 +140,31 @@ contains !=============================================================================== ! PETSC_INIT_MPI !=============================================================================== -! -! subroutine petsc_init_mpi() -! -! integer :: new_comm ! new communicator -! integer :: orig_group ! original MPI group for MPI_COMM_WORLD -! integer :: new_group ! new MPI group subset of orig_group -! integer,allocatable :: ranks(:) ! ranks to include for petsc -! integer :: k ! iteration counter -! -! ! set ranks 0-6 or min -! if (n_procs >= 6) then -! if (.not. allocated(ranks)) allocate(ranks(0:5)) -! ranks = (/0,1,2,3,4,5/) -! else -! if (.not. allocated(ranks)) allocate(ranks(0:n_procs-1)) -! ranks = (/(k,k=0,n_procs-1)/) -! end if -! -! ! get the original mpi group -! call MPI_COMM_GROUP(MPI_COMM_WORLD,orig_group,mpi_err) -! -! ! new group init -! call MPI_GROUP_INCL(orig_group,size(ranks),ranks,new_group,mpi_err) -! -! ! create new communicator -! call MPI_COMM_CREATE(MPI_COMM_WORLD,new_group,new_comm,mpi_err) -! -! ! deallocate ranks -! if (allocated(ranks)) deallocate(ranks) -! -! ! set PETSC_COMM_WORLD to this subset -! PETSC_COMM_WORLD = new_comm -! -! end subroutine petsc_init_mpi - -!=============================================================================== -! PETSC_INIT_MPI -!=============================================================================== - + subroutine petsc_init_mpi() - + integer :: new_comm ! new communicator integer :: orig_group ! original MPI group for MPI_COMM_WORLD integer :: new_group ! new MPI group subset of orig_group integer,allocatable :: ranks(:) ! ranks to include for petsc integer :: k ! iteration counter - integer :: nprocs - - nprocs = 1 - - ! set ranks 0-6 or min - if (nprocs >= 6) then - if (.not. allocated(ranks)) allocate(ranks(0:5)) - ranks = (/0,1,2,3,4,5/) - else - if (.not. allocated(ranks)) allocate(ranks(0:nprocs-1)) - ranks = (/(k,k=0,nprocs-1)/) - end if - + + ! set ranks + if (.not. allocated(ranks)) allocate(ranks(0:n_procs_cmfd - 1)) + ranks = (/(k,k=0,n_procs_cmfd - 1)/) + ! get the original mpi group call MPI_COMM_GROUP(MPI_COMM_WORLD,orig_group,mpi_err) - + ! new group init call MPI_GROUP_INCL(orig_group,size(ranks),ranks,new_group,mpi_err) - + ! create new communicator call MPI_COMM_CREATE(MPI_COMM_WORLD,new_group,new_comm,mpi_err) - + ! deallocate ranks if (allocated(ranks)) deallocate(ranks) - + ! set PETSC_COMM_WORLD to this subset PETSC_COMM_WORLD = new_comm diff --git a/src/cmfd_input.F90 b/src/cmfd_input.F90 index 945b6d32b2..74e74690d3 100644 --- a/src/cmfd_input.F90 +++ b/src/cmfd_input.F90 @@ -93,6 +93,10 @@ contains ! create tally objects call create_cmfd_tally() + ! set number of CMFD processors and report to user + n_procs_cmfd = n_cmfd_procs_ + if (master) write(*,*) "CMFD Running on",n_procs_cmfd," processors." + end subroutine read_cmfd_xml !=============================================================================== diff --git a/src/xml-fortran/templates/cmfd_t.xml b/src/xml-fortran/templates/cmfd_t.xml index 0d9c6eec97..f99a8c4d14 100644 --- a/src/xml-fortran/templates/cmfd_t.xml +++ b/src/xml-fortran/templates/cmfd_t.xml @@ -15,5 +15,6 @@ +