Fixed synchronization counter update for pwr6 kernels
[gromacs.git] / src / gmxlib / nonbonded / nb_kernel_power6 / nb_kernel_pwr6sync.c
blobb3b9354b7dde8bc9ba881acd7dbfe69d0854e4b6
1 /*
2 * This source code is part of
4 * G R O M A C S
6 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
7 * Copyright (c) 2001-2009, The GROMACS Development Team
9 * Gromacs is a library for molecular simulation and trajectory analysis,
10 * written by Erik Lindahl, David van der Spoel, Berk Hess, and others - for
11 * a full list of developers and information, check out http://www.gromacs.org
13 * This program is free software; you can redistribute it and/or modify it under
14 * the terms of the GNU Lesser General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option) any
16 * later version.
17 * As a special exception, you may use this file as part of a free software
18 * library without restriction. Specifically, if other files instantiate
19 * templates or use macros or inline functions from this file, or you compile
20 * this file and link it with other files to produce an executable, this
21 * file does not by itself cause the resulting executable to be covered by
22 * the GNU Lesser General Public License.
24 * In plain-speak: do not worry about classes/macros/templates either - only
25 * changes to the library have to be LGPL, not an application linking with it.
27 * To help fund GROMACS development, we humbly ask that you cite
28 * the papers people have written on it - you can find them on the website!
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
36 #ifdef HAVE_PTHREAD_H
37 #include <pthread.h>
38 #endif
40 #include <stdio.h>
42 /*! \brief Lock innerloop mutex and read lists indices
44 * \internal
46 * This routine is only used when both Fortran innerloops
47 * and threads are enabled.
49 * Since the Fortran77 standard does not include support
50 * for POSIX threads, we call this routine instead which
52 * - Locks the provided mutex
53 * - Reads the counter from memory
54 * - Advances the counter in successively smaller chunks
55 * - Releases the mutex
57 * In other words, it performs exactly the same action as
58 * we do natively in the nonbonded kernel outer loop
59 * when using C language for the kernels.
61 * Fortran does not know anything about a mutex, but since
62 * arguments are passed by reference we mask it as a pointer
63 * to an integer in the Fortran code.
65 * \param mtx Pointer to the mutex to use, masked as int
66 * \param count Pointer to the outer loop counter
67 * \param nri Total umber of (outer loop) neighborlists
68 * \param nthreads Number of working threads
69 * \param nn0 Returned value: Low index to use for outerloop
70 * \param nn1 Returned value: High index to use for outerloop
72 * \warning There is one possible cause of problems. Some
73 * fortran compilers make all variables static by
74 * default, and that will obviously screw up
75 * multithreading in a major way. If your Fortran
76 * compiler does this you only have two alternatives:
77 * Either find the flag to turn it off, or compile
78 * Gromacs without any Fortran nonbonded kernels.
80 void
81 F77_FUNC(pwr6kernelsync,PWR6KERNELSYNC)
82 (int * mtx,
83 int * count,
84 int * nri,
85 int * nthreads,
86 int * nn0,
87 int * nn1)
89 int n0,n1;
92 #ifdef HAVE_PTHREADS_H
93 pthread_mutex_lock((pthread_mutex_t *)mtx);
94 #endif
95 n0 = *count;
96 /* Take successively smaller chunks */
97 n1 = n0+((*nri)-n0)/(2*(*nthreads))+3;
98 *count = n1;
99 #ifdef HAVE_PTHREADS_H
100 pthread_mutex_unlock((pthread_mutex_t *)mtx);
101 #endif
102 *nn0 = n0;
103 *nn1 = n1;