if(OPENMP_FOUND)
set(GROMACS_C_FLAGS "${OpenMP_C_FLAGS} ${GROMACS_C_FLAGS}")
set(GROMACS_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${GROMACS_CXX_FLAGS}")
- add_definitions(-DGMX_OPENMP)
else(OPENMP_FOUND)
message(WARNING
"Compiler not supporting OpenMP. This might hurt your performance a lot, "
--- /dev/null
+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+ *
+ *
+ * This source code is part of
+ *
+ * G R O M A C S
+ *
+ * GROningen MAchine for Chemical Simulations
+ *
+ * Written by the Gromacs development team under coordination of
+ * David van der Spoel, Berk Hess, and Erik Lindahl.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org
+ *
+ * And Hey:
+ * GROup of MAchos and Cynical Suckers
+ */
+
+#ifndef GMX_OMP_H
+#define GMX_OMP_H
+
+/* This module defines wrappers for OpenMP API functions and enables compiling
+ * code even when OpenMP is turned off in the build system.
+ * Therfore, OpenMP API functions should always be used through these wrappers
+ * and omp.h should never be directly included. Instead, this header should be
+ * used whnever OpenMP API functions are needed.
+ */
+
+/*! Sets the number of threads in subsequent parallel regions, unless overridden
+ * by a num_threads clause. Acts as a wrapper for omp_get_max_threads(void). */
+int gmx_omp_get_max_threads(void);
+
+/*! Returns the thread number of the thread executing within its thread team.
+ * Acts as a warpper for omp_get_thread_num(void). */
+int gmx_omp_get_thread_num(void);
+
+/*! Returns an integer that is equal to or greater than the number of threads
+ * that would be available if a parallel region without num_threads were
+ * defined at that point in the code. Acts as a wapepr for omp_set_num_threads(void). */
+void gmx_omp_set_num_threads(int num_threads);
+
+#endif /* GMX_OMP_H */
(MPI or thread_mpi) */
#cmakedefine GMX_MPI
-/* Use threads for parallelization */
+/* Use threads_mpi for parallelization */
#cmakedefine GMX_THREAD_MPI
+/* Use OpenMP multithreading */
+#cmakedefine GMX_OPENMP
+
/* Use old threading (domain decomp force calc) code */
#cmakedefine GMX_THREAD_SHM_FDECOMP
--- /dev/null
+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+ *
+ *
+ * This source code is part of
+ *
+ * G R O M A C S
+ *
+ * GROningen MAchine for Chemical Simulations
+ *
+ * Written by the Gromacs development team under coordination of
+ * David van der Spoel, Berk Hess, and Erik Lindahl.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org
+ *
+ * And Hey:
+ * Gnomes, ROck Monsters And Chili Sauce
+ */
+
+#ifdef HAVE_CONFIG
+#include "config.h"
+#endif
+
+#ifdef GMX_OPENMP
+#include <omp.h>
+#endif
+
+#include "gmx_omp.h"
+
+int gmx_omp_get_max_threads(void)
+{
+#ifdef GMX_OPENMP
+ return omp_get_max_threads();
+#else
+ return 1;
+#endif
+}
+
+
+int gmx_omp_get_thread_num(void)
+{
+#ifdef GMX_OPENMP
+ return omp_get_thread_num();
+#else
+ return 0;
+#endif
+}
+
+void gmx_omp_set_num_threads(int num_threads)
+{
+#ifdef GMX_OPENMP
+ omp_set_num_threads(num_threads);
+#else
+ return;
+#endif
+}
#include "membed.h"
#include "md_openmm.h"
+#include "gmx_omp.h"
+
#ifdef GMX_LIB_MPI
#include <mpi.h>
#endif
#include "md_openmm.h"
#endif
-#ifdef GMX_OPENMP
-#include <omp.h>
-#endif
-
typedef struct {
gmx_integrator_t *func;
{
cpu_set_t mask;
CPU_ZERO(&mask);
- core+=omp_get_thread_num();
+ core+=gmx_omp_get_thread_num();
CPU_SET(core,&mask);
sched_setaffinity((pid_t) syscall (SYS_gettid),sizeof(cpu_set_t),&mask);
}
#endif
#ifdef GMX_OPENMP
+/* TODO: Do we still need this? Are we still planning ot use fftw + OpenMP? */
#define FFT5D_THREADS
#endif
#ifdef FFT5D_THREADS
-#include <omp.h>
+#include "gmx_omp.h"
/* requires fftw compiled with openmp */
/* #define FFT5D_FFTW_THREADS (now set by cmake) */
#endif
#include "tmpi.h"
#endif
-#ifdef GMX_OPENMP
-#include <omp.h>
-#endif
+#include "gmx_omp.h"
#include <stdio.h>
#include <string.h>
#include "smalloc.h"
#include "vec.h"
#include "geminate.h"
+#include "gmx_omp.h"
-#ifdef DOUSEOPENMP
-#define HAVE_OPENMP
-#endif
-#ifdef HAVE_OPENMP
-#include <omp.h>
-#endif
/* The first few sections of this file contain functions that were adopted,
* and to some extent modified, by Erik Marklund (erikm[aT]xray.bmc.uu.se,
part3 = gem_cxmul(gamma, gem_cxmul(gem_cxadd(alpha, beta) , gem_cxsub(alpha, beta))); /* 3(1+2)(1-2) */
part4 = gem_cxmul(gem_cxsub(gamma, alpha), gem_cxmul(gem_cxsub(alpha, beta), gem_cxsub(beta, gamma))); /* (3-1)(1-2)(2-3) */
-#ifdef HAVE_OPENMP
#pragma omp parallel for \
private(i, tsqrt, oma, omb, omc, c1, c2, c3, c4), \
reduction(+:sumimaginary), \
default(shared), \
schedule(guided)
-#endif
for (i=0; i<manytimes; i++){
tsqrt = sqrt(time[i]);
oma = gem_comega(gem_cxrmul(alpha, tsqrt));
fixGemACF(GD->ctTheory, nFitPoints);
/* Removing a bunch of points from the log-part. */
-#ifdef HAVE_OPENMP
#pragma omp parallel for schedule(dynamic) \
firstprivate(nData, ctTheory, y, nFitPoints) \
private (i, iLog, r) \
reduction(+:residual2) \
default(shared)
-#endif
for(i=0; i<nFitPoints; i++)
{
iLog = GD->logtime[i];
#ifdef HAVE_LIBGSL
#ifdef HAVE_OPENMP
- nThreads = omp_get_num_procs();
- omp_set_num_threads(nThreads);
+ nThreads = gmx_omp_get_max_threads();
+ gmx_omp_set_num_threads(nThreads);
fprintf(stdout, "We will be using %i threads.\n", nThreads);
#endif
/* #if (_OPENMP >= 200805) /\* =====================\ *\/ */
/* nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, omp_get_thread_limit()); */
/* #else */
- nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, omp_get_num_procs());
+ nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, gmx_omp_get_num_procs());
/* #endif /\* _OPENMP >= 200805 ====================/ *\/ */
- omp_set_num_threads(nThreads);
+ gmx_omp_set_num_threads(nThreads);
snew(dondata, nThreads);
for (i=0; i<nThreads; i++)
dondata[i] = -1;
default(shared)
{
#pragma omp barrier
- thisThread = omp_get_thread_num();
+ thisThread = gmx_omp_get_thread_num();
rhbex = NULL;
#endif /* ==============================================/ */
{ /* ########## THE START OF THE ENORMOUS PARALLELIZED BLOCK! ########## */
h = NULL;
g = NULL;
- thisThread = omp_get_thread_num();
+ thisThread = gmx_omp_get_thread_num();
snew(h,hb->maxhydro);
snew(g,hb->maxhydro);
mMax = INT_MIN;
/* #if (_OPENMP > 200805) */
/* actual_nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, omp_get_thread_limit()); */
/* #else */
- actual_nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, omp_get_num_procs());
+ actual_nThreads = min((nThreads <= 0) ? INT_MAX : nThreads, gmx_omp_get_num_procs());
/* #endif */
- omp_set_num_threads(actual_nThreads);
+ gmx_omp_set_num_threads(actual_nThreads);
printf("Frame loop parallelized with OpenMP using %i threads.\n", actual_nThreads);
fflush(stdout);
}
bGem, oenv, fnm, fpnhb, trrStatus, natoms, \
status, nabin, nrbin, adist, rdist, debug)
{ /* Start of parallel region */
- threadNr = omp_get_thread_num();
+ threadNr = gmx_omp_get_thread_num();
#endif /* HAVE_OPENMP ================================================= */
do
{
#include "matio.h"
#include "gmx_ana.h"
#include "nsfactor.h"
-
-#ifdef GMX_OPENMP
-#include <omp.h>
-#endif
-
+#include "gmx_omp.h"
int gmx_sans(int argc,char *argv[])
{
{ efXVG, "-pr", "pr", ffWRITE }
};
-#ifdef GMX_OPENMP
- nthreads = omp_get_max_threads();
-#endif
+ nthreads = gmx_omp_get_max_threads();
CopyRight(stderr,argv[0]);
parse_common_args(&argc,argv,PCA_BE_NICE,
check_mcover(mcover);
/* setting number of omp threads globaly */
-#ifdef GMX_OPENMP
- omp_set_num_threads(nthreads);
-#endif
+ gmx_omp_set_num_threads(nthreads);
+
/* Now try to parse opts for modes */
switch(emethod[0][0]) {
case 'd':
#include "strdb.h"
#include "vec.h"
#include "nsfactor.h"
-
-#ifdef GMX_OPENMP
-#include <omp.h>
-#endif
+#include "gmx_omp.h"
void check_binwidth(real binwidth) {
real smallest_bin=0.1;
}
rng=gmx_rng_init(seed);
#ifdef GMX_OPENMP
- nthreads = omp_get_max_threads();
+ nthreads = gmx_omp_get_max_threads();
snew(tgr,nthreads);
snew(trng,nthreads);
for(i=0;i<nthreads;i++){
}
#pragma omp parallel shared(tgr,trng,mc) private(tid,i,j)
{
- tid = omp_get_thread_num();
+ tid = gmx_omp_get_thread_num();
/* now starting parallel threads */
#pragma omp for
for(mc=0;mc<max;mc++) {
gmx_rng_destroy(rng);
} else {
#ifdef GMX_OPENMP
- nthreads = omp_get_max_threads();
+ nthreads = gmx_omp_get_max_threads();
/* Allocating memory for tgr arrays */
snew(tgr,nthreads);
for(i=0;i<nthreads;i++) {
}
#pragma omp parallel shared(tgr) private(tid,i,j)
{
- tid = omp_get_thread_num();
+ tid = gmx_omp_get_thread_num();
/* starting parallel threads */
#pragma omp for
for(i=0;i<isize;i++) {