JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.08k stars 5.43k forks source link

free_memory reports garbage #44843

Open PetrKryslUCSD opened 2 years ago

PetrKryslUCSD commented 2 years ago

At the moment tested only on Windows 10 with Julia 1.7.2.

At random intervals, free_memory will report totally wrong number of bytes (note the second invocation):

└ @ C:\Users\pkonl\Documents\00WIP\FinEtoolsDeforLinear.jl\Manifest.toml:0                                                                       
               _                                                                                                                                 
   _       _ _(_)_     |  Documentation: https://docs.julialang.org                                                                              
  (_)     | (_) (_)    |                                                                                                                         
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.                                                                                  
  | | | | | | |/ _` |  |                                                                                                                         
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)                                                                                             
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release                                                                                
|__/                   |                                                                                                                         

julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\FinEtoolsDeforLinear.jl\\examples\\statics\\3-d\\stubby_corbel_examples.jl")                 
Stubby corbel example. Element: H8                                                                                                               

Initial free memory = 9666.7 [MB]                                                                                                                
Number of elements: 32000                                                                                                                        
After mesh, free memory decrease = 11.8 [MB]                                                                                                     
u.nfreedofs = 101680                                                                                                                             
Before stiffness, free memory decrease = 29.9 [MB]                                                                                               
After stiffness, free memory decrease = 886.2 [MB]                                                                                               
Stiffness: number of non zeros = 6771050 [ND]                                                                                                    
                  Sparsity Pattern                                                                                                               
          ┌──────────────────────────────┐                                                                                                       
        1 │:::.                          │ > 0                                                                                                   
          │'::::.                        │ < 0                                                                                                   
          │  '::::.                      │                                                                                                       
          │    '::::.                    │                                                                                                       
          │      '::::.                  │                                                                                                       
          │        '::::.                │                                                                                                       
          │          '::::.              │                                                                                                       
          │            '::::.            │                                                                                                       
          │              ':::.           │                                                                                                       
          │                 '::.         │                                                                                                       
          │                   '::.       │                                                                                                       
          │                     '::.     │                                                                                                       
          │                       '::.   │                                                                                                       
          │                         '::. │                                                                                                       
   101680 │                           '::│                                                                                                       
          └──────────────────────────────┘                                                                                                       
           1                       101680                                                                                                        
                  6771050 nonzeros                                                                                                               
 11.659005 seconds (43.25 k allocations: 3.166 GiB, 1.08% gc time, 0.46% compilation time)                                                       
After factorization, free memory decrease = 2758.9 [MB]                                                                                          
  0.238532 seconds (9.57 k allocations: 3.648 MiB, 6.10% compilation time)                                                                       
After solution, free memory decrease = 2758.3 [MB]                                                                                               
Deflection: [-1.51762e-01], compared to -1.26000e+01                                                                                             
true                                                                                                                                             

julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\FinEtoolsDeforLinear.jl\\examples\\statics\\3-d\\stubby_corbel_examples.jl")                 
WARNING: replacing module stubby_corbel_examples.                                                                                                
Stubby corbel example. Element: H8                                                                                                               

Initial free memory = 6848.4 [MB]                                                                                                                
Number of elements: 32000                                                                                                                        
After mesh, free memory decrease = 17592186044407.3 [MB]                                                                                         
u.nfreedofs = 101680                                                                                                                             
Before stiffness, free memory decrease = 17592186041634.2 [MB]                                                                                   
After stiffness, free memory decrease = 17592186042413.6 [MB]                                                                                    
Stiffness: number of non zeros = 6771050 [ND]                                                                                                    
                  Sparsity Pattern                                                                                                               
          ┌──────────────────────────────┐                                                                                                       
        1 │:::.                          │ > 0                                                                                                   
          │'::::.                        │ < 0                                                                                                   
          │  '::::.                      │                                                                                                       
          │    '::::.                    │                                                                                                       
          │      '::::.                  │                                                                                                       
          │        '::::.                │                                                                                                       
          │          '::::.              │                                                                                                       
          │            '::::.            │                                                                                                       
          │              ':::.           │                                                                                                       
          │                 '::.         │                                                                                                       
          │                   '::.       │                                                                                                       
          │                     '::.     │                                                                                                       
          │                       '::.   │                                                                                                       
          │                         '::. │                                                                                                       
   101680 │                           '::│                                                                                                       
          └──────────────────────────────┘                                                                                                       
           1                       101680                                                                                                        
                  6771050 nonzeros                                                                                                               
 11.651395 seconds (55 allocations: 3.157 GiB, 1.86% gc time)                                                                                    
After factorization, free memory decrease = 17592186044309.4 [MB]                                                                                
  0.219337 seconds (18 allocations: 3.160 MiB)                                                                                                   
After solution, free memory decrease = 17592186044317.2 [MB]                                                                                     
Deflection: [-1.51762e-01], compared to -1.26000e+01                                                                                             
true      

In the third invocation of the script, free_memory breaks halfway through:

julia> include("C:\\Users\\pkonl\\Documents\\00WIP\\FinEtoolsDeforLinear.jl\\examples\\statics\\3-d\\stubby_corbel_examples.jl")                 
WARNING: replacing module stubby_corbel_examples.                                                                                                
Stubby corbel example. Element: H8                                                                                                               

Initial free memory = 6845.4 [MB]                                                                                                                
Number of elements: 32000                                                                                                                        
After mesh, free memory decrease = 2.3 [MB]                                                                                                      
u.nfreedofs = 101680                                                                                                                             
Before stiffness, free memory decrease = 179.4 [MB]                                                                                              
After stiffness, free memory decrease = 17592186042576.9 [MB]                                                                                    
Stiffness: number of non zeros = 6771050 [ND]                                                                                                    
                  Sparsity Pattern                                                                                                               
          ┌──────────────────────────────┐                                                                                                       
        1 │:::.                          │ > 0                                                                                                   
          │'::::.                        │ < 0                                                                                                   
          │  '::::.                      │                                                                                                       
          │    '::::.                    │                                                                                                       
          │      '::::.                  │                                                                                                       
          │        '::::.                │                                                                                                       
          │          '::::.              │                                                                                                       
          │            '::::.            │                                                                                                       
          │              ':::.           │                                                                                                       
          │                 '::.         │                                                                                                       
          │                   '::.       │                                                                                                       
          │                     '::.     │                                                                                                       
          │                       '::.   │                                                                                                       
          │                         '::. │                                                                                                       
   101680 │                           '::│                                                                                                       
          └──────────────────────────────┘                                                                                                       
           1                       101680                                                                                                        
                  6771050 nonzeros                                                                                                               
 11.307348 seconds (55 allocations: 3.157 GiB, 1.44% gc time)                                                                                    
After factorization, free memory decrease = 17592186044352.7 [MB]                                                                                
  0.248417 seconds (18 allocations: 3.160 MiB, 2.13% gc time)                                                                                    
After solution, free memory decrease = 17592186044352.7 [MB]                                                                                     
Deflection: [-1.51762e-01], compared to -1.26000e+01                                                                                             
true                       
JeffBezanson commented 2 years ago

Looks like a negative number cast to unsigned? It says "decrease" so I assume the calling code is computing a difference. Can you confirm whether free_memory itself is returning a bad value?

PetrKryslUCSD commented 2 years ago

Yes, the difference is between the reading of the free memory initially and the subsequent reading. So, yes, I suspect the subsequent memory reads return a negative value.

PetrKryslUCSD commented 1 year ago

Has this been fixed in 1.8 or 1.9 by any chance?