Skip to content

Commit 10f8833

Browse files
Test the Poisson solver in parallel
1 parent b671eef commit 10f8833

File tree

3 files changed

+16
-59
lines changed

3 files changed

+16
-59
lines changed

src/petsc/poisson_cg.f90

Lines changed: 14 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ subroutine create_operator(self, n)
223223
integer :: ierr
224224

225225
call MatCreateShell(PETSC_COMM_WORLD, n, n, PETSC_DETERMINE, &
226-
PETSC_DETERMINE, self%ctx, self%Amat, ierr)
226+
PETSC_DETERMINE, self%ctx, self%Amat, ierr)
227227
call MatShellSetContext(self%Amat, self%ctx, ierr) ! Is this necessary?
228228
call MatShellSetOperation(self%Amat, MATOP_MULT, poissmult_petsc, ierr)
229229
call MatSetUp(self%Amat, ierr)
@@ -297,62 +297,11 @@ subroutine create_preconditioner(self, mesh, n)
297297
coeffs(7) = 1 / dz**2
298298
cols(6) = cols(1) - (dims(1) + 2) * (dims(2) + 2)
299299
cols(7) = cols(1) + (dims(1) + 2) * (dims(2) + 2)
300-
301-
! coeffs = 0
302-
! cols = -1 ! Set null (simplifies BCs)
303-
! cols(1) = row
304-
305-
! ! d2pdx2
306-
! coeffs(1) = coeffs(1) - 2 / dx**2
307-
! coeffs(2) = 1 / dx**2
308-
! coeffs(3) = 1 / dx**2
309-
! if (i > 1) then
310-
! cols(2) = cols(1) - 1
311-
! else
312-
! cols(2) = cols(1) + (dims(1) - i)
313-
! end if
314-
! if (i < dims(1)) then
315-
! cols(3) = cols(1) + 1
316-
! else
317-
! cols(3) = cols(1) - (dims(1) - 1)
318-
! end if
319-
320-
! ! d2pdy2
321-
! coeffs(1) = coeffs(1) - 2 / dy**2
322-
! coeffs(4) = 1 / dy**2
323-
! coeffs(5) = 1 / dy**2
324-
! if (j > 1) then
325-
! cols(4) = cols(1) - dims(1)
326-
! else
327-
! cols(4) = cols(1) + (dims(2) - j) * dims(1)
328-
! end if
329-
! if (j < dims(2)) then
330-
! cols(5) = cols(1) + dims(1)
331-
! else
332-
! cols(5) = cols(1) - (dims(2) - 1) * dims(1)
333-
! end if
334-
335-
! ! d2pdz2
336-
! coeffs(1) = coeffs(1) - 2 / dz**2
337-
! coeffs(6) = 1 / dz**2
338-
! coeffs(7) = 1 / dz**2
339-
! if (k > 1) then
340-
! cols(6) = cols(1) - dims(2) * dims(1)
341-
! else
342-
! cols(6) = cols(1) + (dims(3) - k) * dims(2) * dims(1)
343-
! end if
344-
! if (k < dims(3)) then
345-
! cols(7) = cols(1) + dims(2) * dims(1)
346-
! else
347-
! cols(7) = cols(1) - (dims(3) - 1) * dims(2) * dims(1)
348-
! end if
349300

350301
! Push to matrix
351302
! Recall Fortran (1-based) -> C (0-based) indexing
352303
call MatSetValuesLocal(self%Pmat, 1, row - 1, nnb + 1, cols - 1, coeffs, &
353-
INSERT_VALUES, ierr)
354-
! call MatSetValues(self%Pmat, 1, row - 1, nnb + 1, cols - 1, coeffs, &
355-
! INSERT_VALUES, ierr)
304+
INSERT_VALUES, ierr)
356305

357306
! Advance row counter
358307
row = row + 1
@@ -480,17 +429,21 @@ subroutine build_neighbour_index_map(idx, mesh, global_start)
480429
nproc = mesh%par%nproc
481430
tag = mesh%par%nrank * max(nproc, 6)
482431
do d = 1, 3
483-
! Recv left and right
432+
!! Recv left and right
433+
! Right Recv
484434
nbtag = mesh%par%pnext(d) * max(nproc, 6)
485435
call MPI_IRecv(info(:, 2, d), 4, MPI_INTEGER, mesh%par%pnext(d), nbtag + 2 * (d - 1) + 1, &
486436
MPI_COMM_WORLD, requests(4 * (d - 1) + 1), ierr)
437+
! Left Recv
487438
nbtag = mesh%par%pprev(d) * max(nproc, 6)
488439
call MPI_IRecv(info(:, 1, d), 4, MPI_INTEGER, mesh%par%pprev(d), nbtag + 2 * (d - 1) + 2, &
489440
MPI_COMM_WORLD, requests(4 * (d - 1) + 2), ierr)
490441

491-
! Send left and right
442+
!! Send left and right
443+
! Left Send
492444
call MPI_ISend(myinfo, 4, MPI_INTEGER, mesh%par%pprev(d), tag + 2 * (d - 1) + 1, &
493445
MPI_COMM_WORLD, requests(4 * (d - 1) + 3), ierr)
446+
! Right Send
494447
call MPI_ISend(myinfo, 4, MPI_INTEGER, mesh%par%pnext(d), tag + 2 * (d - 1) + 2, &
495448
MPI_COMM_WORLD, requests(4 * (d - 1) + 4), ierr)
496449
end do
@@ -521,7 +474,7 @@ subroutine build_neighbour_index_map(idx, mesh, global_start)
521474
end associate
522475

523476
!! Y halos
524-
! Left halo
477+
! Bottom halo
525478
associate(offset_down => info(1, 1, 2), &
526479
nx_down => info(2, 1, 2), ny_down => info(3, 1, 2), nz_down => info(4, 1, 2))
527480
ctr = offset_down + (ny_down - 1) * nx_down ! Global starting index -> yend
@@ -534,7 +487,7 @@ subroutine build_neighbour_index_map(idx, mesh, global_start)
534487
ctr = ctr + (nx_down * ny_down) ! Step in k
535488
end do
536489
end associate
537-
! Right halo
490+
! Top halo
538491
associate(offset_up => info(1, 2, 2), &
539492
nx_up => info(2, 2, 2), ny_up => info(3, 2, 2), nz_up => info(4, 2, 2))
540493
ctr = offset_up ! Global starting index == ystart
@@ -549,7 +502,7 @@ subroutine build_neighbour_index_map(idx, mesh, global_start)
549502
end associate
550503

551504
!! Z halos
552-
! Left halo
505+
! Back halo
553506
associate(offset_back => info(1, 1, 3), &
554507
nx_back => info(2, 1, 3), ny_back => info(3, 1, 3), nz_back => info(4, 1, 3))
555508
ctr = offset_back + ny_back * nx_back ! Global starting index -> zend
@@ -560,7 +513,7 @@ subroutine build_neighbour_index_map(idx, mesh, global_start)
560513
end do
561514
end do
562515
end associate
563-
! Right halo
516+
! Front halo
564517
associate(offset_front => info(1, 2, 3), &
565518
nx_front => info(2, 2, 3), ny_front => info(3, 2, 3), nz_front => info(4, 2, 3))
566519
ctr = offset_front ! Global startin index == zstart
@@ -657,6 +610,8 @@ subroutine poissmult_petsc(M, x, f, ierr)
657610

658611
type(mat_ctx_t) :: ctx
659612

613+
ierr = 0;
614+
660615
! XXX: Fixme
661616
! call MatShellGetContext(M, ctx, ierr)
662617
! print *, ctx%foo

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ endif()
5353
define_test(test_poisson_cg_eval.f90 1 omp)
5454
define_test(test_poisson_cg_eval.f90 ${CMAKE_CTEST_NPROCS} omp)
5555
define_test(test_poisson_cg_solve.f90 1 omp)
56+
define_test(test_poisson_cg_solve.f90 ${CMAKE_CTEST_NPROCS} omp)

tests/test_poisson_cg_solve.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ subroutine teardown()
241241
print *, "PASS"
242242
else
243243
print *, "FAIL"
244+
stop 1
244245
end if
245246
end if
246247

0 commit comments

Comments
 (0)