~jon-hill/fluidity/diagnostic_check

« back to all changes in this revision

Viewing changes to femtools/Sparse_Tools_Petsc.F90

  • Committer: Stephan Kramer
  • Date: 2013-11-06 11:48:34 UTC
  • Revision ID: s.kramer@imperial.ac.uk-20131106114834-c3b1sw349dkjktr2
BUG-FIX: unsafe storage of halos on petsc_csr_matrix. Only a pointer to the 
passed in halo was stored in the allocate routines, which means that the halo 
would be invalidated if the halo is deallocated before the matrix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
241
241
    if (associated(sparsity%row_halo)) then
242
242
      ! these are also pointed to in the row_numbering
243
243
      ! but only refcounted here
244
 
      matrix%row_halo => sparsity%row_halo
 
244
      allocate(matrix%row_halo)
 
245
      matrix%row_halo = sparsity%row_halo
245
246
      call incref(matrix%row_halo)
246
247
    end if
247
248
    
248
249
    if (associated(sparsity%column_halo)) then
249
250
      ! these are also pointed to in the column_numbering
250
251
      ! but only refcounted here
251
 
      matrix%column_halo => sparsity%column_halo
 
252
      allocate(matrix%column_halo)
 
253
      matrix%column_halo = sparsity%column_halo
252
254
      call incref(matrix%column_halo)
253
255
    end if
254
256
    
429
431
    if (associated(lrow_halo)) then
430
432
      ! these are also pointed to in the row_numbering
431
433
      ! but only refcounted here
432
 
      matrix%row_halo => lrow_halo
 
434
      allocate(matrix%row_halo)
 
435
      matrix%row_halo = lrow_halo
433
436
      call incref(matrix%row_halo)
434
437
    end if
435
438
    
436
439
    if (associated(lcolumn_halo)) then
437
440
      ! these are also pointed to in the column_numbering
438
441
      ! but only refcounted here
439
 
      matrix%column_halo => lcolumn_halo
 
442
      allocate(matrix%column_halo)
 
443
      matrix%column_halo = lcolumn_halo
440
444
      call incref(matrix%column_halo)
441
445
    end if
442
446
    
478
482
    call incref(matrix%column_numbering)
479
483
    
480
484
    if (associated(row_numbering%halo)) then
481
 
      matrix%row_halo => row_numbering%halo
 
485
      allocate(matrix%row_halo)
 
486
      matrix%row_halo = row_numbering%halo
482
487
      call incref(row_numbering%halo)
483
488
    end if
484
489
    
485
490
    if (associated(column_numbering%halo)) then
486
 
      matrix%column_halo => column_numbering%halo
 
491
      allocate(matrix%column_halo)
 
492
      matrix%column_halo = column_numbering%halo
487
493
      call incref(column_numbering%halo)
488
494
    end if
489
495
    
540
546
    
541
547
    if (associated(matrix%row_halo)) then
542
548
       call deallocate(matrix%row_halo)
 
549
       deallocate(matrix%row_halo)
543
550
    end if
544
551
    
545
552
    if (associated(matrix%column_halo)) then
546
553
       call deallocate(matrix%column_halo)
 
554
       deallocate(matrix%column_halo)
547
555
    end if
548
556
    
549
557
42  if (present(stat)) then
911
919
    call incref(c%column_numbering)
912
920
    
913
921
    if (associated(a%row_halo)) then
914
 
      c%row_halo => a%row_halo
 
922
      allocate(c%row_halo)
 
923
      c%row_halo = a%row_halo
915
924
      call incref(c%row_halo)
916
925
    else
917
926
      nullify(c%row_halo)
918
927
    end if
919
928
    if (associated(a%column_halo)) then
920
 
      c%column_halo => a%column_halo
 
929
      allocate(c%column_halo)
 
930
      c%column_halo = a%column_halo
921
931
      call incref(c%column_halo)
922
932
    else
923
933
      nullify(c%column_halo)