From owner-freebsd-questions@FreeBSD.ORG Thu Feb 2 09:55:19 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DA34A106564A for ; Thu, 2 Feb 2012 09:55:19 +0000 (UTC) (envelope-from mexas@bristol.ac.uk) Received: from dirj.bris.ac.uk (dirj.bris.ac.uk [137.222.10.78]) by mx1.freebsd.org (Postfix) with ESMTP id 8FB368FC1F for ; Thu, 2 Feb 2012 09:55:19 +0000 (UTC) Received: from ncsc.bris.ac.uk ([137.222.10.41]) by dirj.bris.ac.uk with esmtp (Exim 4.72) (envelope-from ) id 1RstNs-0003Bd-Mu; Thu, 02 Feb 2012 09:55:16 +0000 Received: from mech-cluster241.men.bris.ac.uk ([137.222.187.241]) by ncsc.bris.ac.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1RstNs-0003ut-AU; Thu, 02 Feb 2012 09:55:16 +0000 Received: from mech-cluster241.men.bris.ac.uk (localhost [127.0.0.1]) by mech-cluster241.men.bris.ac.uk (8.14.5/8.14.5) with ESMTP id q129tG7M078479; Thu, 2 Feb 2012 09:55:16 GMT (envelope-from mexas@bris.ac.uk) Received: (from mexas@localhost) by mech-cluster241.men.bris.ac.uk (8.14.5/8.14.5/Submit) id q129tFRo078478; Thu, 2 Feb 2012 09:55:15 GMT (envelope-from mexas@bris.ac.uk) X-Authentication-Warning: mech-cluster241.men.bris.ac.uk: mexas set sender to mexas@bris.ac.uk using -f Date: Thu, 2 Feb 2012 09:55:15 +0000 From: Anton Shterenlikht To: Dennis Glatting Message-ID: <20120202095515.GA78375@mech-cluster241.men.bris.ac.uk> Mail-Followup-To: Dennis Glatting , Anton Shterenlikht , freebsd-questions@freebsd.org References: <20120202000947.GA71405@mech-cluster241.men.bris.ac.uk> <1328142599.53835.6.camel@btw.pki2.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1328142599.53835.6.camel@btw.pki2.com> User-Agent: Mutt/1.4.2.3i Cc: Anton Shterenlikht , freebsd-questions@freebsd.org Subject: Re: OpenMP on FreeBSD X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Feb 2012 09:55:20 -0000 On Wed, Feb 01, 2012 at 04:29:59PM -0800, Dennis Glatting wrote: > On Thu, 2012-02-02 at 00:09 +0000, Anton Shterenlikht wrote: > > I'm new to OpenMP. I wonder > > if there are any special considerations > > when running OpenMP on FreeBSD? > > > > I run OpenMP. No special consideration. Here's a chunk from my Makefile: > > TARG=ecc.enc ecc.dec > > $TARG: *.cc *.h Makefile > g++ -Wall -fopenmp -g -O ${INCL} ${LIBS} -o ecc.enc *.cc > g++ -Wall -fopenmp -g -O ${INCL} ${LIBS} -o ecc.dec *.cc > > > > For example, I have this OMP parallelised > > fortran program, nested do loops, compiled > > with gfortran46. When I run it with 2 threads > > on a 2-cpu box, I see in top(1): > > > > PID UID PRI NICE SIZE RES STATE C TIME CPU COMMAND > > 63995 1001 89 0 57048K 34272K CPU1 1 1:06 55.08% dummy.sx{dummy.sx} > > 63995 1001 87 0 57048K 34272K RUN 1 1:02 52.39% dummy.sx{dummy.sx} > > 11 0 155 ki31 0K 32K RUN 0 376:58 51.46% idle{idle: cpu0} > > 11 0 155 ki31 0K 32K RUN 1 368:18 45.36% idle{idle: cpu1} > > > > I wonder why, even after a minute of run time, > > I still have nearly a whole cpu idle? > > > > What is the program doing? I/O can significantly limit OMP value. Also, > you need to make sure you code your loops properly or else you have a > single-threaded application, without warning. Here's my parallel bit: !$OMP PARALLEL DEFAULT(NONE) & !$OMP SHARED(AEND,SPACE1,SPACE2,SIZE1,SIZE2,SIZE3) & !$OMP PRIVATE(STEP,RANDN,X1,X2,X3) !$OMP DO SCHEDULE(RUNTIME) DO X3 = 1,SIZE3 DO X2 = 1,SIZE2 DO X1 = 1,SIZE1 IF(SPACE1(X1,X2,X3).EQ.0) THEN AEND = .FALSE. ! UPDATE AT LEAST ONE CELL CALL RANDOM_NUMBER(RANDN) ! 0 <= RANDN < 1 STEP = NINT(RANDN*2-1) ! STEP = [-1 0 1] SPACE2(X1,X2,X3) = SPACE1(X1+STEP(1),X2+STEP(2),X3+STEP(3)) END IF END DO END DO END DO !$OMP END DO !$OMP END PARALLEL There's no I/O at all. Not sure what you mean by proper looping. The threads are definitely created. I use "setenv OMP_NUM_THREADS" to set the number of threads. Then I monitor thread creation with top -H. The number of threads shown there matches what I set. So I'm pretty sure the executable is multi-threaded. Perhaps I should explore various SCHEDULE options? By the way, what sort of speed-up do you see with your loop? And what ratio threads/cores is optimal for you? Many thanks -- Anton Shterenlikht Room 2.6, Queen's Building Mech Eng Dept Bristol University University Walk, Bristol BS8 1TR, UK Tel: +44 (0)117 331 5944 Fax: +44 (0)117 929 4423