1 /************************************************************
2 * HMMER - Biological sequence analysis with profile HMMs
3 * Copyright (C) 1992-1999 Washington University School of Medicine
6 * This source code is distributed under the terms of the
7 * GNU General Public License. See the files COPYING and LICENSE
9 ************************************************************/
12 * SRE, Fri Jul 10 10:05:44 1998
14 * Pthreads code shared by hmmsearch, hmmcalibrate, and hmmpfam
15 * to coarse-grain parallelize on platforms capable of POSIX
16 * threads. Most of the threads code, however, is in the respective
17 * main's, i.e. hmmsearch.c, hmmpfam.c, hmmcalibrate.c
19 * RCS $Id: threads.c,v 1.1.1.1 2005/03/22 08:34:02 cmzmasek Exp $
22 #ifdef HMMER_THREADS /* conditional inclusion of the entire file */
35 /* Function: ThreadNumber()
36 * Date: SRE, Sat Jul 11 11:03:50 1998 [St. Louis]
38 * Purpose: Recommend how many threads to use.
40 * - if we can determine the number of processors
41 * on the machine by SQD_NPROC, use that. This
42 * should succeed for SGI IRIX, Digital UNIX, and
43 * Sun Solaris platforms.
44 * - if not, assume two processors. We're probably
45 * on a FreeBSD or Linux box, and odds are that its
47 * - if HMMER_NCPU is defined in config.h, use that
48 * number instead; allows Linux or FreeBSD machines
49 * to compile code for a quadprocessor, for instance.
50 * That define can be overridden at compile
51 * time by a -DHMMER_NCPU=x, where x is the
53 * - if HMMER_NCPU is defined in the environment,
54 * use that number, overriding all others.
56 * Typically, we'll set the default number of
57 * threads with ThreadNumber() but allow it
58 * to be overridden at the command line with --cpu.
60 * Summarizing priority:
62 * environment variable, setenv HMMER_NCPU x
63 * compile-time, MDEFS=HMMER_NCPU=x
64 * compile-time, config.h definition of HMMER_NCPU
65 * SQD_NPROC, or 2 if SQD_NPROC doesn't work.
69 * Returns: >= 1, recommended number of threads
77 num = SQD_NPROC; /* SGI, Sun, Digital: get # of available CPUs */
78 if (num == -1) num = 2; /* Linux, FreeBSD: assume dualprocessor */
80 num = HMMER_NCPU; /* allow config.h to override; usually we don't */
82 /* allow environment variable to override */
83 if ((env = getenv("HMMER_NCPU")) != NULL)
85 if (num <= 0) num = 1; /* silent sanity check */
86 SQD_DPRINTF1(("ThreadNumber(): setting number of threads to %d\n", num));
90 #endif /*HMMER_THREADS*/