From owner-freebsd-fortran@FreeBSD.ORG Sat Aug 24 20:36:33 2013 Return-Path: Delivered-To: fortran@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id B857646D for ; Sat, 24 Aug 2013 20:36:33 +0000 (UTC) (envelope-from mexas@bristol.ac.uk) Received: from eu1sys200aog118.obsmtp.com (eu1sys200aog118.obsmtp.com [207.126.144.145]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 109E321DC for ; Sat, 24 Aug 2013 20:36:32 +0000 (UTC) Received: from mail-wg0-f41.google.com ([74.125.82.41]) (using TLSv1) by eu1sys200aob118.postini.com ([207.126.147.11]) with SMTP ID DSNKUhkZLTleRPLXyDSVBDfe7iTzE+FajenG@postini.com; Sat, 24 Aug 2013 20:36:33 UTC Received: by mail-wg0-f41.google.com with SMTP id c11so2693046wgh.4 for ; Sat, 24 Aug 2013 13:35:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:date:from:message-id:to:subject:cc :reply-to:in-reply-to; bh=c8WTyocoZrV6CUVG0yWpDBxkiPbyKHBKy07TC2NWnJQ=; b=AXW1ftGx+cEEzcYYw/Pxqb7gkkUi5Dir26nSYoYEKzbQYGtAhhfqnbMK8v6DgES7iC n8i2YLx+AeiB9VzRCGFQhBnONdt+jzrL7Bx3DRDWpCt43ansPW+F9HcxsUbnEHYkS2Uy pj2wf7vQ61+z6i1eJPVfjx7eQZpq2K85+ufpq0AiynoILZ/HF4FXOogrnz03uwM66oZb yNw36ObvriaEc+NhktLEdnCQSuM7kpdyLUjyfwau4VYnNsqcFkRfn4pBRvjNsuv8Tc3O tZezaJ94XAAFOsm2OCKBNzZlUCiSA+nWidYuFpQo1WxUKqvAisAXAnbygjGwhU3JSDOR e+0Q== X-Gm-Message-State: ALoCoQkLhseTrdYVzDTF0XjeLTrYxBP8DoHK9LBmrI29KvQL9FFKjwPfu6g7ojHpR+2eBNyXPXzL/zbiGPWrTY/cWShLGToRfJsAaamegqiz6xU1o2nvWZczIM9HQ50HSqRnmMd4rqOtnmXkoEqKsN/5mNoZ/LY/Cw== X-Received: by 10.180.160.203 with SMTP id xm11mr2392545wib.17.1377376556954; Sat, 24 Aug 2013 13:35:56 -0700 (PDT) X-Received: by 10.180.160.203 with SMTP id xm11mr2392540wib.17.1377376556887; Sat, 24 Aug 2013 13:35:56 -0700 (PDT) Received: from mech-cluster241.men.bris.ac.uk (mech-cluster241.men.bris.ac.uk. [137.222.187.241]) by mx.google.com with ESMTPSA id jf9sm6658344wic.5.1969.12.31.16.00.00 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 24 Aug 2013 13:35:55 -0700 (PDT) Sender: Anton Shterenlikht Received: from mech-cluster241.men.bris.ac.uk (localhost [127.0.0.1]) by mech-cluster241.men.bris.ac.uk (8.14.7/8.14.6) with ESMTP id r7OKZrKf059462 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 24 Aug 2013 21:35:53 +0100 (BST) (envelope-from mexas@mech-cluster241.men.bris.ac.uk) Received: (from mexas@localhost) by mech-cluster241.men.bris.ac.uk (8.14.7/8.14.6/Submit) id r7OKZrbU059461; Sat, 24 Aug 2013 21:35:53 +0100 (BST) (envelope-from mexas) Date: Sat, 24 Aug 2013 21:35:53 +0100 (BST) From: Anton Shterenlikht Message-Id: <201308242035.r7OKZrbU059461@mech-cluster241.men.bris.ac.uk> To: mexas@bris.ac.uk, sgk@troutmask.apl.washington.edu Subject: Re: lazy memory allocation In-Reply-To: <20130823171042.GA47588@troutmask.apl.washington.edu> Cc: fortran@freebsd.org X-BeenThere: freebsd-fortran@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: mexas@bris.ac.uk List-Id: Fortran on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Aug 2013 20:36:33 -0000 >From sgk@troutmask.apl.washington.edu Fri Aug 23 19:28:09 2013 > >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.) ok, thanks for this hint >You can also add in STAT and ERRMSG after SOURCE to >inspect whether allocation was successful. That's the thing. I had it, like in integer :: errstat=0 allocate(a(10),stat=errstat) if (errstat .ne. 0) stop "some msg" And didn't get stopped, i.e. errstat was zero on exit from ALLOCATE. The segfault happened on a = some_value Anton