Skip to content
Snippets Groups Projects
Commit e19fa798 authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Move toward autotools

parent 967371f8
No related branches found
No related tags found
1 merge request!5Last commit before huge rework
# This file is part of PySWIFTsim.
# Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Add the non-standard paths to the included library headers
AM_CFLAGS = -I$(top_srcdir)/src $(HDF5_CPPFLAGS) $(GSL_INCS) $(FFTW_INCS) $(NUMA_INCS) $(GRACKLE_INCS) $(PYTHON_INCS)
# Assign a "safe" version number
AM_LDFLAGS = $(HDF5_LDFLAGS) $(FFTW_LIBS) -version-info 0:0:0
# The git command, if available.
GIT_CMD = @GIT_CMD@
# Additional dependencies for shared libraries.
EXTRA_LIBS = $(HDF5_LIBS) $(FFTW_LIBS) $(NUMA_LIBS) $(PROFILER_LIBS) $(TCMALLOC_LIBS) \
$(JEMALLOC_LIBS) $(TBBMALLOC_LIBS) $(GRACKLE_LIBS) $(GSL_LIBS) $(PYTHON_LIBS) \
$(top_srcdir)/src/.libs
# MPI libraries.
MPI_LIBS = $(PARMETIS_LIBS) $(METIS_LIBS) $(MPI_THREAD_LIBS)
MPI_FLAGS = -DWITH_MPI $(PARMETIS_INCS) $(METIS_INCS)
# Build the libswiftsim library
lib_LTLIBRARIES = libpyswiftsim.la
# Build a MPI-enabled version too?
if HAVEMPI
lib_LTLIBRARIES += libpyswiftsim_mpi.la
endif
# List required headers
include_HEADERS = chemistry_wrapper.h cooling_wrapper.h \
cosmology_wrapper.h parser_wrapper.h part_wrapper.h \
pyswiftsim_tools.h units_wrapper.h
# Common source files
AM_SOURCES = chemistry_wrapper.c cooling_wrapper.c cosmology_wrapper.c \
parser_wrapper.c part_wrapper.c pyswiftsim_tools.c \
units_wrapper.c wrapper.c
# Include files for distribution, not installation.
nobase_noinst_HEADERS =
# Sources and flags for regular library
libpyswiftsim_la_SOURCES = $(AM_SOURCES)
libpyswiftsim_la_CFLAGS = $(AM_CFLAGS)
libpyswiftsim_la_LDFLAGS = $(AM_LDFLAGS) $(EXTRA_LIBS) -lswiftsim
libpyswiftsim_la_LIBADD = $(GRACKLE_LIBS) $(VELOCIRAPTOR_LIBS)
# Sources and flags for MPI library
libpyswiftsim_mpi_la_SOURCES = $(AM_SOURCES)
libpyswiftsim_mpi_la_CFLAGS = $(AM_CFLAGS) $(MPI_FLAGS)
libpyswiftsim_mpi_la_LDFLAGS = $(AM_LDFLAGS) $(MPI_LIBS) $(EXTRA_LIBS) -lswiftsim_mpi
libpyswiftsim_mpi_la_SHORTNAME = mpi
libpyswiftsim_mpi_la_LIBADD = $(GRACKLE_LIBS) $(VELOCIRAPTOR_LIBS)
/*******************************************************************************
* This file is part of PYSWIFTSIM.
* Copyright (c) 2018 loic hausammann (loic.hausammann@epfl.ch)
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef __PYSWIFTSIM_CONFIG_H__
#define __PYSWIFTSIM_CONFIG_H__
#include "pyswiftsim_tools.h"
/**
* @brief give the cooling type name
*
* @return Cooling name (PyUnicode)
*/
PyObject* config_get_cooling() {
char *cooling_name = "Not implemented";
/* lambda */
#ifdef COOLING_CONST_LAMBDA
cooling_name = "const_lambda";
/* grackle */
#elif defined(COOLING_GRACKLE)
#if COOLING_GRACKLE_MODE == 0
cooling_name = "grackle";
#elif COOLING_GRACKLE_MODE == 1
cooling_name = "grackle1";
#elif COOLING_GRACKLE_MODE == 2
cooling_name = "grackle2";
#elif COOLING_GRACKLE_MODE == 3
cooling_name = "grackle3";
#else
error("Grackle mode unknown");
#endif // COOLING_GRACKLE_MODE
#endif // COOLING_GRACKLE
return PyUnicode_FromString(cooling_name);
};
#endif // __PYSWIFTSIM_CONFIG_H__
...@@ -114,7 +114,7 @@ void pycooling_set_fractions(struct xpart *xp, PyArrayObject* frac, const int id ...@@ -114,7 +114,7 @@ void pycooling_set_fractions(struct xpart *xp, PyArrayObject* frac, const int id
* @param args arguments * @param args arguments
* @return cooling rate * @return cooling rate
*/ */
PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { PyObject* pycooling_rate(PyObject* self, PyObject* args) {
import_array(); import_array();
PyObject *pycooling; PyObject *pycooling;
...@@ -190,13 +190,12 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -190,13 +190,12 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
struct xpart xp; struct xpart xp;
/* return object */ /* return object */
PyArrayObject *rate = PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT); PyArrayObject *rate = (PyArrayObject *)PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
/* Release GIL */ /* Release GIL */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
/* loop over all particles */ /* loop over all particles */
#pragma omp for
for(size_t i = 0; i < N; i++) for(size_t i = 0; i < N; i++)
{ {
/* set particle data */ /* set particle data */
...@@ -214,7 +213,10 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -214,7 +213,10 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
/* compute cooling rate */ /* compute cooling rate */
#ifdef COOLING_GRACKLE #ifdef COOLING_GRACKLE
float *tmp = PyArray_GETPTR1(rate, i); float *tmp = PyArray_GETPTR1(rate, i);
*tmp = cooling_rate(pconst, us, cosmo, cooling, &p, &xp, dt); *tmp = cooling_new_energy(pconst, us, cosmo, cooling, &p, &xp, dt);
*tmp = *tmp - hydro_get_physical_internal_energy(&p, &xp, cosmo);
*tmp /= dt;
message("%g", *tmp);
#else #else
message("Not implemented"); message("Not implemented");
//*tmp = cooling_rate(pconst, us, cosmo, cooling, &p, &xp); //*tmp = cooling_rate(pconst, us, cosmo, cooling, &p, &xp);
...@@ -224,7 +226,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -224,7 +226,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
/* Acquire GIL */ /* Acquire GIL */
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
return rate; return (PyObject *) rate;
} }
...@@ -241,7 +243,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) { ...@@ -241,7 +243,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
* @param args arguments * @param args arguments
* @return New energy * @return New energy
*/ */
PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) { PyObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
import_array(); import_array();
PyObject *pycooling; PyObject *pycooling;
...@@ -322,13 +324,12 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) { ...@@ -322,13 +324,12 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
#endif #endif
/* return object */ /* return object */
PyArrayObject *new_energy = PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT); PyArrayObject *new_energy = (PyArrayObject *)PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
/* Release GIL */ /* Release GIL */
Py_BEGIN_ALLOW_THREADS; Py_BEGIN_ALLOW_THREADS;
/* loop over all particles */ /* loop over all particles */
#pragma omp for
for(size_t i = 0; i < N; i++) for(size_t i = 0; i < N; i++)
{ {
/* set particle data */ /* set particle data */
...@@ -358,6 +359,6 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) { ...@@ -358,6 +359,6 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
/* Acquire GIL */ /* Acquire GIL */
Py_END_ALLOW_THREADS; Py_END_ALLOW_THREADS;
return new_energy; return (PyObject *) new_energy;
} }
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
PyObject* pycooling_init(PyObject* self, PyObject* args); PyObject* pycooling_init(PyObject* self, PyObject* args);
PyArrayObject* pycooling_rate(PyObject* self, PyObject* args); PyObject* pycooling_rate(PyObject* self, PyObject* args);
PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args); PyObject* pycooling_do_cooling(PyObject* self, PyObject* args);
#endif // __PYSWIFTSIM_COOLING_H__ #endif // __PYSWIFTSIM_COOLING_H__
...@@ -137,7 +137,7 @@ char* pytools_get_type_name(PyObject *obj) ...@@ -137,7 +137,7 @@ char* pytools_get_type_name(PyObject *obj)
pyerror("Requires a non null object"); pyerror("Requires a non null object");
/* get object type */ /* get object type */
PyObject *type = obj->ob_type; PyObject *type = (PyObject *)obj->ob_type;
if (type == NULL) if (type == NULL)
pyerror("Unable to get type"); pyerror("Unable to get type");
......
...@@ -25,7 +25,8 @@ ...@@ -25,7 +25,8 @@
#include <numpy/arrayobject.h> #include <numpy/arrayobject.h>
#undef assert #undef assert
#include <swift.h> #include "../config.h"
#include "swift.h"
#define DIM 3 #define DIM 3
#define STRING_SIZE 200 #define STRING_SIZE 200
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "cosmology_wrapper.h" #include "cosmology_wrapper.h"
#include "chemistry_wrapper.h" #include "chemistry_wrapper.h"
#include "pyswiftsim_tools.h" #include "pyswiftsim_tools.h"
#include "config_wrapper.h" #include "swift.h"
#include <Python.h> #include <Python.h>
#include <math.h> #include <math.h>
...@@ -91,9 +91,6 @@ static PyMethodDef wrapper_methods[] = { ...@@ -91,9 +91,6 @@ static PyMethodDef wrapper_methods[] = {
"\t Energy of the particle after dt\n" "\t Energy of the particle after dt\n"
}, },
{"configGetCooling", config_get_cooling, METH_VARARGS,
"Get the cooling type."},
{NULL, NULL, 0, NULL} /* Sentinel */ {NULL, NULL, 0, NULL} /* Sentinel */
}; };
...@@ -104,11 +101,15 @@ static struct PyModuleDef wrapper_cmodule = { ...@@ -104,11 +101,15 @@ static struct PyModuleDef wrapper_cmodule = {
"wrapper", "wrapper",
"Wrapper around the SPH cosmological simulation code SWIFT", "Wrapper around the SPH cosmological simulation code SWIFT",
-1, -1,
wrapper_methods wrapper_methods,
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
}; };
PyMODINIT_FUNC PyInit_wrapper(void) PyMODINIT_FUNC PyInit_libpyswiftsim(void)
{ {
PyObject *m; PyObject *m;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment