From owner-freebsd-fortran@FreeBSD.ORG Fri Aug 23 17:10:46 2013 Return-Path: Delivered-To: fortran@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id E83316DC for ; Fri, 23 Aug 2013 17:10:46 +0000 (UTC) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id AE6B02502 for ; Fri, 23 Aug 2013 17:10:46 +0000 (UTC) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.7/8.14.7) with ESMTP id r7NHAg7l047702; Fri, 23 Aug 2013 10:10:42 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.7/8.14.7/Submit) id r7NHAgAP047701; Fri, 23 Aug 2013 10:10:42 -0700 (PDT) (envelope-from sgk) Date: Fri, 23 Aug 2013 10:10:42 -0700 From: Steve Kargl To: Anton Shterenlikht Subject: Re: lazy memory allocation Message-ID: <20130823171042.GA47588@troutmask.apl.washington.edu> References: <201308231025.r7NAPwNH043266@mech-cluster241.men.bris.ac.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201308231025.r7NAPwNH043266@mech-cluster241.men.bris.ac.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: fortran@freebsd.org X-BeenThere: freebsd-fortran@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Fortran on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Aug 2013 17:10:47 -0000 On Fri, Aug 23, 2013 at 11:25:58AM +0100, Anton Shterenlikht wrote: > I've been burned by what's apparently called > "lazy memory allocation" on linux. > > My code calls a subroutine that allocates > a coarray. This routine exits fine, with > no error. However, when I tried to initialise > the coarray, I got segfault. On investigation > I discovered that the coarray was not in fact > allocated. In my particular case this was > because there was not enough memory. > > Anyway, I was later told that this is an > expected behaviour on linux, with its > "lazy memory allocation". > > I'm wondering if FreeBSD also uses > a lazy memory allocation, or we do it differently? man malloc. FreeBSD uses jemalloc, which allows one to tune the allocators behavior. I suspect, but have not tried to verify, that by default it uses lazy memory allocation. To avoid possible issues with lazy memory allocation, initialize the memory. real, allocatable :: a(:) allocate(a(10) :: source=0.) You can also add in STAT and ERRMSG after SOURCE to inspect whether allocation was successful. -- Steve