From owner-freebsd-questions@FreeBSD.ORG Thu Feb 2 00:30:22 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 CCEB31065673 for ; Thu, 2 Feb 2012 00:30:22 +0000 (UTC) (envelope-from freebsd@pki2.com) Received: from btw.pki2.com (btw.pki2.com [IPv6:2001:470:a:6fd::2]) by mx1.freebsd.org (Postfix) with ESMTP id 7D7C98FC13 for ; Thu, 2 Feb 2012 00:30:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by btw.pki2.com (8.14.5/8.14.5) with ESMTP id q120TxIG055724; Wed, 1 Feb 2012 16:29:59 -0800 (PST) (envelope-from freebsd@pki2.com) From: Dennis Glatting To: Anton Shterenlikht In-Reply-To: <20120202000947.GA71405@mech-cluster241.men.bris.ac.uk> References: <20120202000947.GA71405@mech-cluster241.men.bris.ac.uk> Content-Type: text/plain; charset="ISO-8859-1" Date: Wed, 01 Feb 2012 16:29:59 -0800 Message-ID: <1328142599.53835.6.camel@btw.pki2.com> Mime-Version: 1.0 X-Mailer: Evolution 2.32.1 FreeBSD GNOME Team Port Content-Transfer-Encoding: 7bit X-yoursite-MailScanner-Information: Dennis Glatting X-yoursite-MailScanner-ID: q120TxIG055724 X-yoursite-MailScanner: Found to be clean X-MailScanner-From: freebsd@pki2.com Cc: 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 00:30:22 -0000 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. > As a result the run time with 2 threads > is nearly identical to run time with 1 thread. > > It's likely that I'm not using OMP correctly, > but I wanted to check if there are any > special FreeBSD related issues to bear > in mind when coding with OMP. > As an example, this is one of my key sections of code in C++. It works. I can't say for Fortran. #pragma omp parallel { #pragma omp for for( size_t i = 0; i < bq.size(); ++i ) { Block& b = bq[ i ]; // Adjust any padding. // if( b.size() != b.szSYMS ) { eofPad = ( b.szSYMS - b.size()); for( ssize_t j = b.size(); j < b.szSYMS; ++j ) b.syms()[ j ] = eofPad; if( verbose ) fprintf( stderr, "Padding: read=%ld, pad=%d\n", b.size(), eofPad ); b.size( b.szSYMS ); } // Encode the buffer. // encode_rs_8( b.syms(), b.parity(), 0 ); // Set it to its new size. // (the encoder is an outside routine.) // b.size( b.szBLOCK ); // Interleave the buffer. // add_interleave( b.buf()); } /* for */ } /* pragma */ > Thanks >