Skip to content

Commit 4cd90a2

Browse files
authored
Merge pull request #258 from OpenSEMBA/MPI-problem-with-MTLN
[WIP] Investigating possible changes to MTL MPI . Problems with cables along the frontier between MPI layers
2 parents a9795b4 + 84b0960 commit 4cd90a2

File tree

12 files changed

+373
-74
lines changed

12 files changed

+373
-74
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ option(SEMBA_FDTD_MAIN_LIB "Compiles main library" ON)
2828
option(SEMBA_FDTD_COMPONENTS_LIB "Compiles components library" ON)
2929
option(SEMBA_FDTD_OUTPUTS_LIB "Compiles outputs library" ON)
3030
# Compilation defines.
31+
if(CMAKE_BUILD_TYPE MATCHES "Release" OR CMAKE_BUILD_TYPE MATCHES "release" )
32+
add_definitions(-DCompileWithRelease)
33+
else()
34+
add_definitions(-DCompileWithDebug)
35+
endif()
3136
if(SEMBA_FDTD_ENABLE_SMBJSON)
3237
add_definitions(-DCompileWithSMBJSON)
3338
endif()

src_main_pub/observation.F90

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4038,6 +4038,9 @@ subroutine FlushMTLNObservationFiles(nEntradaRoot, mtlnProblem)
40384038
unit = 2000
40394039
do i = 1, size(mtln_solver%bundles)
40404040
do j = 1, size(mtln_solver%bundles(i)%probes)
4041+
#ifdef CompileWithMPI
4042+
if (.not. mtln_solver%bundles(i)%probes(j)%in_layer) cycle
4043+
#endif
40414044
path = trim(trim(nEntradaRoot)//"_"//trim(mtln_solver%bundles(i)%probes(j)%name)//".dat")
40424045
open (unit=unit, file=trim(path))
40434046
write (*, *) 'name: ', trim(mtln_solver%bundles(i)%probes(j)%name)

src_main_pub/timestepping.F90

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,14 +1139,14 @@ end subroutine initializeLumped
11391139

11401140
subroutine initializeWires()
11411141
real (kind=rkind_tiempo) :: dtcritico, newdtcritico
1142-
! real (kind=rkind) :: dtcritico, newdtcritico
11431142
character(len=BUFSIZE) :: dubuf, buff
11441143
logical :: l_auxinput, l_auxoutput
11451144
#ifdef CompileWithMPI
11461145
integer(kind=4) :: ierr
11471146
#endif
11481147

11491148
dtcritico=this%sgg%dt
1149+
#ifndef CompileWithMTLN
11501150
if ((trim(adjustl(this%control%wiresflavor))=='holland') .or. &
11511151
(trim(adjustl(this%control%wiresflavor))=='transition')) then
11521152
#ifdef CompileWithMPI
@@ -1234,10 +1234,21 @@ subroutine initializeWires()
12341234
endif
12351235
endif
12361236
#endif
1237+
1238+
1239+
#else
1240+
! else of #ifndef CompileWithMTLN
1241+
#ifdef CompileWithMPI
1242+
call MPI_Barrier(SUBCOMM_MPI,ierr)
1243+
#endif
1244+
write(dubuf,*) 'Init MTLN Wires...'; call print11(this%control%layoutnumber,dubuf)
1245+
call InitWires_mtln(this%sgg,Ex,Ey,Ez,this%eps0, this%mu0, this%mtln_parsed,this%thereAre%MTLNbundles, dtcritico)
1246+
#endif
1247+
1248+
12371249
!!!sincroniza el dtcritico
12381250
#ifdef CompileWithMPI
12391251
newdtcritico = 0.0
1240-
! call MPI_AllReduce( dtcritico, newdtcritico, 1_4, REALSIZE, MPI_MIN, SUBCOMM_MPI, ierr)
12411252
call MPI_AllReduce( dtcritico, newdtcritico, 1_4, REALSIZE_tiempo, MPI_MIN, SUBCOMM_MPI, ierr)
12421253
dtcritico=newdtcritico
12431254
#endif
@@ -1246,7 +1257,11 @@ subroutine initializeWires()
12461257
if ((this%control%layoutnumber==0).and.this%control%verbose) call WarnErrReport(buff)
12471258
else
12481259
if (.not.(this%control%resume.and.this%control%permitscaling)) then !no abortasr solo advertir si permittivity scaling
1260+
#ifdef CompileWithMTLN
1261+
write(buff,'(a,e10.2e3)') 'WIR_ERROR: Possibly UNSTABLE dt, make dt < ',dtcritico
1262+
#else
12491263
write(buff,'(a,e10.2e3)') 'WIR_ERROR: Possibly UNSTABLE dt, decrease wire radius, number of parallel WIREs, use -stableradholland or make dt < ',dtcritico
1264+
#endif
12501265
if (this%control%layoutnumber==0) call WarnErrReport(buff,.true.)
12511266
else
12521267
write(buff,'(a,e10.2e3)') 'WIR_WARNING: Resume and Pscaling with wires. Possibly UNSTABLE dt, decrease wire radius, number of parallel WIREs: dt is over ',dtcritico
@@ -1255,15 +1270,6 @@ subroutine initializeWires()
12551270
endif
12561271
!!!
12571272
!!
1258-
#ifdef CompileWithMTLN
1259-
#ifdef CompileWithMPI
1260-
call MPI_Barrier(SUBCOMM_MPI,ierr)
1261-
#endif
1262-
write(dubuf,*) 'Init MTLN Wires...'; call print11(this%control%layoutnumber,dubuf)
1263-
call InitWires_mtln(this%sgg,Ex,Ey,Ez,Idxh,Idyh,Idzh,this%eps0, this%mu0, this%mtln_parsed,this%thereAre%MTLNbundles)
1264-
#else
1265-
write(buff,'(a)') 'WIR_ERROR: Executable was not compiled with MTLN modules.'
1266-
#endif
12671273

12681274
end subroutine initializeWires
12691275

src_mtln/mtl.F90

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ module mtl_mod
1414
integer, parameter :: COMM_SEND = 1
1515
integer, parameter :: COMM_RECV = -1
1616
integer, parameter :: COMM_NONE = 0
17+
integer, parameter :: COMM_FIELD = 1
18+
integer, parameter :: COMM_V = 2
19+
integer, parameter :: COMM_BOTH = 3
1720

1821
type, public :: communicator_t
1922
integer :: field_index = -1, v_index = -1
2023
integer :: comm_task = COMM_NONE
24+
integer :: comm_type = COMM_NONE
2125
integer :: delta_rank = 0
2226
end type
2327
type, public :: comm_t
@@ -180,7 +184,7 @@ function mtl_unshielded(lpul, cpul, rpul, gpul, &
180184
call res%initStepSizeAndFieldSegments(step_size, segments, layer_indices)
181185
call res%initCommunicators(alloc_z)
182186
res%layer_indices = layer_indices
183-
res%bundle_in_layer = bundle_in_layer
187+
res%bundle_in_layer = bundle_in_layer
184188
else
185189
res%step_size = step_size
186190
allocate(res%layer_indices(0,0))
@@ -350,6 +354,7 @@ subroutine initStepSizeAndFieldSegments(this, step_size, segments, layer_indices
350354
if (j /= size(layer_indices,1)) then
351355
this%step_size(n + layer_indices(j,2) - layer_indices(j,1) + 1) = this%step_size(n + layer_indices(j,2) - layer_indices(j,1))
352356
this%segments(n + layer_indices(j,2) - layer_indices(j,1) + 1) = this%segments(n + layer_indices(j,2) - layer_indices(j,1))
357+
this%segments(n + layer_indices(j,2) - layer_indices(j,1) + 1)%orientation = -1
353358
n = n + 1
354359
end if
355360
n = n + layer_indices(j,2) - layer_indices(j,1) + 1
@@ -361,7 +366,7 @@ subroutine initStepSizeAndFieldSegments(this, step_size, segments, layer_indices
361366
subroutine initCommunicators(this, alloc_z)
362367
class(mtl_t) :: this
363368
integer (kind =4), dimension(2) :: alloc_z
364-
integer :: j, n
369+
integer :: j, n, z
365370
integer :: rank, ierr
366371
integer (kind =4) :: z_init, z_end
367372
type(communicator_t), dimension(:), allocatable :: aux_comm
@@ -374,7 +379,33 @@ subroutine initCommunicators(this, alloc_z)
374379
z_end = alloc_z(2)
375380

376381
do j = 1, size(this%segments)
382+
if (this%segments(j)%orientation == -1) cycle
377383

384+
z = this%segments(j)%z
385+
if (.not. isSegmentZOriented(j) .and. ((z == z_end) .or. (z == z_init + 1))) then
386+
387+
n = size(this%mpi_comm%comms)
388+
deallocate(aux_comm)
389+
allocate(aux_comm(n+1))
390+
aux_comm(1:n) = this%mpi_comm%comms
391+
392+
aux_comm(n+1)%field_index = j
393+
aux_comm(n+1)%comm_type = COMM_FIELD
394+
aux_comm(n+1)%v_index = -1
395+
if (z == z_end) then
396+
aux_comm(n+1)%delta_rank = 1
397+
aux_comm(n+1)%comm_task = COMM_RECV
398+
else if (z == z_init + 1) then
399+
aux_comm(n+1)%delta_rank = -1
400+
aux_comm(n+1)%comm_task = COMM_SEND
401+
end if
402+
403+
deallocate(this%mpi_comm%comms)
404+
allocate(this%mpi_comm%comms(n+1))
405+
this%mpi_comm%comms = aux_comm
406+
407+
408+
end if
378409
if (isSegmentZOriented(j) .and. &
379410
(isSegmentNextToLayerEnd(j,z_end) .or. isSegmentNextToLayerInit(j,z_init))) then
380411

@@ -383,6 +414,7 @@ subroutine initCommunicators(this, alloc_z)
383414
allocate(aux_comm(n+1))
384415
aux_comm(1:n) = this%mpi_comm%comms
385416
aux_comm(n+1)%field_index = j
417+
aux_comm(n+1)%comm_type = COMM_BOTH
386418

387419
if (isSegmentNextToLayerEnd(j,z_end)) then
388420
aux_comm(n+1)%delta_rank = 1
@@ -438,7 +470,12 @@ logical function isSegmentZOriented(j)
438470

439471
logical function isSegmentZPositive(j)
440472
integer, intent(in) :: j
441-
isSegmentZPositive = (this%segments(j)%orientation > 0)
473+
isSegmentZPositive = (this%segments(j)%orientation == 3)
474+
end function
475+
476+
logical function isSegmentZNegative(j)
477+
integer, intent(in) :: j
478+
isSegmentZNegative = (this%segments(j)%orientation == -3)
442479
end function
443480

444481
logical function isSegmentBeforeLayerEnd(j, z_end)
@@ -473,14 +510,14 @@ logical function isSegmentNextToLayerEnd(j, z_end)
473510
integer, intent(in) :: j, z_end
474511
integer :: z
475512
z = this%segments(j)%z
476-
isSegmentNextToLayerEnd = (abs(z-z_end)<= 1)
513+
isSegmentNextToLayerEnd = (z==z_end) .or. (z==z_end-1)
477514
end function
478515

479516
logical function isSegmentNextToLayerInit(j, z_init)
480517
integer, intent(in) :: j, z_init
481518
integer :: z
482519
z = this%segments(j)%z
483-
isSegmentNextToLayerInit = (abs(z-z_init-1) <= 1)
520+
isSegmentNextToLayerInit = (z==z_init) .or. (z==z_init+1)
484521
end function
485522

486523

src_mtln/mtl_bundle.F90

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ subroutine Comm_MPI_V(this)
403403
call MPI_COMM_RANK(SUBCOMM_MPI, rank, ierr)
404404
number_of_conductors = size(this%v,1)
405405
do i = 1, size(this%mpi_comm%comms)
406+
if (this%mpi_comm%comms(i)%comm_type == COMM_V .or. this%mpi_comm%comms(i)%comm_type == COMM_BOTH) then
406407
if (this%mpi_comm%comms(i)%comm_task == COMM_SEND) then
407408
do c = 1, number_of_conductors
408409
call MPI_send(this%v(c, this%mpi_comm%comms(i)%v_index),1, REALSIZE, &
@@ -419,6 +420,7 @@ subroutine Comm_MPI_V(this)
419420
SUBCOMM_MPI, status, ierr)
420421
end do
421422
end if
423+
end if
422424
end do
423425

424426

@@ -429,17 +431,19 @@ subroutine Comm_MPI_Fields(this)
429431
integer :: i, ierr, rank, status(MPI_STATUS_SIZE)
430432
call MPI_COMM_RANK(SUBCOMM_MPI, rank, ierr)
431433
do i = 1, size(this%mpi_comm%comms)
432-
if (this%mpi_comm%comms(i)%comm_task == COMM_SEND) then
433-
call MPI_send(this%external_field_segments(this%mpi_comm%comms(i)%field_index)%field, 1, REALSIZE, &
434-
rank+this%mpi_comm%comms(i)%delta_rank, &
435-
100*(rank+this%mpi_comm%comms(i)%delta_rank+1), &
436-
SUBCOMM_MPI, ierr)
437-
end if
438-
if (this%mpi_comm%comms(i)%comm_task == COMM_RECV) then
439-
call MPI_recv(this%external_field_segments(this%mpi_comm%comms(i)%field_index)%field,1, REALSIZE, &
440-
rank+this%mpi_comm%comms(i)%delta_rank, &
441-
100*(rank+1), &
442-
SUBCOMM_MPI, status, ierr)
434+
if (this%mpi_comm%comms(i)%comm_type == COMM_FIELD .or. this%mpi_comm%comms(i)%comm_type == COMM_BOTH) then
435+
if (this%mpi_comm%comms(i)%comm_task == COMM_SEND) then
436+
call MPI_send(this%external_field_segments(this%mpi_comm%comms(i)%field_index)%field, 1, REALSIZE, &
437+
rank+this%mpi_comm%comms(i)%delta_rank, &
438+
100*(rank+this%mpi_comm%comms(i)%delta_rank+1), &
439+
SUBCOMM_MPI, ierr)
440+
end if
441+
if (this%mpi_comm%comms(i)%comm_task == COMM_RECV) then
442+
call MPI_recv(this%external_field_segments(this%mpi_comm%comms(i)%field_index)%field,1, REALSIZE, &
443+
rank+this%mpi_comm%comms(i)%delta_rank, &
444+
100*(rank+1), &
445+
SUBCOMM_MPI, status, ierr)
446+
end if
443447
end if
444448
end do
445449
end subroutine

src_mtln/mtln_solver.F90

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ module mtln_solver_mod
1616
type(network_manager_t) :: network_manager
1717
type(probe_t), allocatable, dimension(:) :: probes
1818
integer :: number_of_bundles
19-
! logical :: has_multiwires
2019
integer :: number_of_steps
2120
contains
2221

@@ -70,8 +69,6 @@ function mtlnCtor(parsed, alloc) result(res)
7069
return
7170
end if
7271

73-
! res%has_multiwires = parsed%has_multiwires
74-
7572
res%dt = pre%dt
7673
res%time = 0.0
7774
res%final_time = pre%final_time
@@ -126,6 +123,10 @@ subroutine step_alone(this)
126123
subroutine setExternalLongitudinalField(this)
127124
class(mtln_t) :: this
128125
integer :: i
126+
#ifdef CompileWithMPI
127+
integer :: ierr
128+
call MPI_Barrier(SUBCOMM_MPI,ierr)
129+
#endif
129130
do i = 1, this%number_of_bundles
130131
if (this%bundles(i)%bundle_in_layer) call this%bundles(i)%setExternalLongitudinalField()
131132
end do
@@ -150,10 +151,10 @@ subroutine advanceNWVoltage(this)
150151
integer :: i,j
151152
integer ::b, c, v_idx, i_idx
152153
integer :: n
153-
#ifdef CompileWithMPI
154-
integer (kind=4) :: ierr
155-
call mpi_barrier(subcomm_mpi, ierr)
156-
#endif
154+
! #ifdef CompileWithMPI
155+
! integer (kind=4) :: ierr
156+
! call mpi_barrier(subcomm_mpi, ierr)
157+
! #endif
157158
if (this%number_of_bundles /= 0) then
158159
do i = 1, size(this%network_manager%networks)
159160
do j = 1, size(this%network_manager%networks(i)%nodes)
@@ -191,6 +192,10 @@ subroutine advanceNWVoltage(this)
191192
subroutine advanceBundlesCurrent(this)
192193
class(mtln_t) :: this
193194
integer :: i
195+
#ifdef CompileWithMPI
196+
integer :: ierr
197+
call mpi_barrier(subcomm_mpi, ierr)
198+
#endif
194199
do i = 1, this%number_of_bundles
195200
if (this%bundles(i)%bundle_in_layer) call this%bundles(i)%advanceCurrent()
196201

src_mtln/network_manager.F90

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ function network_managerCtor(networks, description, final_time, dt) result(res)
8383
character(*), dimension(:), intent(in) :: description
8484
real, intent(in) :: final_time, dt
8585
type(network_manager_t) :: res
86-
86+
logical :: printInput = .true.
8787
res%dt = dt
8888
res%time = 0.0
8989
res%networks = networks
9090
call res%circuit%init(copy_node_names(networks), copy_sources(networks))
9191
res%circuit%dt = dt
92-
call res%circuit%readInput(description, .true.)
92+
#ifdef CompileWithRelease
93+
printInput = .false.
94+
#endif
95+
call res%circuit%readInput(description, printInput)
9396
call res%circuit%setModStopTimes(dt)
9497

9598
end function

0 commit comments

Comments
 (0)