#include <string.h>
#include <time.h>
-#ifdef GMX_NATIVE_WINDOWS
-#include <process.h>
-#endif
-#ifdef HAVE_SYS_TIME_H
-#include <sys/time.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
#include "gromacs/fileio/filenm.h"
#include "gromacs/fileio/gmxfio.h"
#include "gromacs/legacyheaders/copyrite.h"
#include "gromacs/utility/gmxmpi.h"
#include "gromacs/utility/programcontext.h"
#include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/sysinfo.h"
/* The source code in this file should be thread-safe.
Please keep it that way. */
time(&t);
-#ifndef NO_GETPID
-# ifdef GMX_NATIVE_WINDOWS
- pid = _getpid();
-# else
- pid = getpid();
-# endif
-#else
- pid = 0;
-#endif
+ pid = gmx_getpid();
if (bAppendFiles)
{
#include <stdlib.h>
#include <time.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef GMX_NATIVE_WINDOWS
-#include <process.h>
-#endif
-
#include "external/Random123-1.08/include/Random123/threefry.h"
#include "gromacs/math/utilities.h"
#include "gromacs/random/random_gausstable.h"
+#include "gromacs/utility/sysinfo.h"
#define RNG_N 624
#define RNG_M 397
else
{
/* No random device available, use time-of-day and process id */
-#ifdef GMX_NATIVE_WINDOWS
- my_pid = (long)_getpid();
-#else
- my_pid = (long)getpid();
-#endif
- data = (unsigned int)(((long)time(NULL)+my_pid) % (long)1000000);
+ my_pid = gmx_getpid();
+ data = (unsigned int)(((long)time(NULL)+my_pid) % (long)1000000);
}
return data;
}
* <H3>Other Functionality</H3>
*
* The header init.h declares gmx::init() and gmx::finalize() for initializing
- * and deinitializing the Gromacs library.
+ * and deinitializing the \Gromacs library.
*
* The header arrayref.h implements a gmx::ConstArrayRef class for exposing a
* C array or part of a std::vector (basically, any continuous stretch of
* The header messagestringcollector.h declares a gmx::MessageStringCollector
* class for composing messages with context information.
*
+ * The header sysinfo.h declares gmx_getpid() for getting the current process
+ * id.
+ *
* The header programcontext.h declares a gmx::ProgramContextInterface that is
* used to
* initialize and access information about the running program, such as the
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS 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.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \internal \file
+ * \brief
+ * Implements functions from sysinfo.h.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \ingroup module_utility
+ */
+#include "gmxpre.h"
+
+#include "sysinfo.h"
+
+#include "config.h"
+
+#ifdef GMX_NATIVE_WINDOWS
+#include <process.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+int gmx_getpid()
+{
+#ifdef GMX_NATIVE_WINDOWS
+ return _getpid();
+#else
+ return getpid();
+#endif
+}
--- /dev/null
+/*
+ * This file is part of the GROMACS molecular simulation package.
+ *
+ * Copyright (c) 2014, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
+ *
+ * GROMACS 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.1
+ * of the License, or (at your option) any later version.
+ *
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
+ *
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
+ */
+/*! \libinternal \file
+ * \brief
+ * Declares functions for obtaining information about the operating environment
+ * and the current process.
+ *
+ * \author Teemu Murtola <teemu.murtola@gmail.com>
+ * \inlibraryapi
+ * \ingroup module_utility
+ */
+#ifndef GMX_UTILITY_SYSINFO_H
+#define GMX_UTILITY_SYSINFO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*! \brief
+ * Returns the process ID of the current process.
+ *
+ * Does not throw.
+ *
+ * \ingroup module_utility
+ */
+int gmx_getpid();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif