Read about our upcoming Code of Conduct on this issue

Commit 5aa345c1 authored by Pierre Augier's avatar Pierre Augier
Browse files

Start to check compatibility between shape and decomposition.

parent a2a509187425
......@@ -178,7 +178,8 @@ def bench_all(dim='2d', n0=1024*2, n1=None, n2=None, path_dir=path_results):
pid = os.getpid()
nfile = (
'result_bench' + dim + '_' + str_grid +
'_' + t_as_str + '_{}'.format(pid) + '.json')
'_{}'.format(mpi.nb_proc) + '_' + t_as_str +
'_{}'.format(pid) + '.json')
path = os.path.join(path_dir, nfile)
......
......@@ -140,6 +140,23 @@ FFT2DMPIWithFFTW1D::~FFT2DMPIWithFFTW1D(void)
}
bool FFT2DMPIWithFFTW1D::are_parameters_bad()
{
if (N0 % nb_proc != 0)
{
if (rank == 0)
cout << "bad parameters: (N0 % nb_proc != 0)" << endl;
return 1;
}
if (N1/2 % nb_proc != 0)
{
if (rank == 0)
cout << "bad parameters: (N1/2 % nb_proc != 0)" << endl;
return 1;
}
return 0;
}
char const* FFT2DMPIWithFFTW1D::get_classname()
{ return "FFT2DMPIWithFFTW1D";}
......
......@@ -7,6 +7,8 @@ class FFT2DMPIWithFFTW1D: public BaseFFT2DMPI
FFT2DMPIWithFFTW1D(int N0, int N1);
~FFT2DMPIWithFFTW1D();
void destroy();
virtual bool are_parameters_bad();
virtual const char* get_classname();
......
......@@ -45,6 +45,10 @@ void BaseFFT::_init()
{
this->_init_parallel();
if (this->are_parameters_bad())
if (rank == 0)
throw invalid_argument("Invalid arguments");
if (rank == 0)
{
cout << endl << "--------" << endl;
......@@ -53,6 +57,11 @@ void BaseFFT::_init()
}
}
bool BaseFFT::are_parameters_bad()
{
return 0;
}
char const* BaseFFT::get_classname()
{ return "BaseFFT";}
......
......@@ -19,6 +19,7 @@ using std::complex;
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <stdexcept>
using namespace std;
......@@ -39,6 +40,7 @@ class BaseFFT
virtual void _init();
virtual void _init_parallel();
virtual bool are_parameters_bad();
virtual const char* get_classname();
......
......@@ -11,18 +11,25 @@ from fluiddyn.util import mpi
cdef class ${class_name}:
"""Class to perform Fast Fourier Transform in 2d."""
cdef int _has_to_destroy
cdef mycppclass* thisptr
cdef tuple _shape_K_loc, _shape_X_loc
def __cinit__(self, int n0=2, int n1=2):
self.thisptr = new mycppclass(n0, n1)
self._has_to_destroy = 1
try:
self.thisptr = new mycppclass(n0, n1)
except ValueError:
self._has_to_destroy = 0
raise
def __init__(self, int n0=2, int n1=2):
self._shape_K_loc = self.get_shapeK_loc()
self._shape_X_loc = self.get_shapeX_loc()
def __dealloc__(self):
self.thisptr.destroy()
if self._has_to_destroy:
self.thisptr.destroy()
del self.thisptr
def get_short_name(self):
......
......@@ -11,6 +11,7 @@ cdef class ${class_name}:
"""Perform fast Fourier transform in 3D.
"""
cdef int _has_to_destroy
cdef mycppclass* thisptr
cdef tuple _shapeK_loc, _shapeX_loc
......@@ -19,7 +20,12 @@ cdef class ${class_name}:
cdef public int nb_proc, rank
def __cinit__(self, int n0=2, int n1=2, int n2=4):
self.thisptr = new mycppclass(n0, n1, n2)
self._has_to_destroy = 1
try:
self.thisptr = new mycppclass(n0, n1, n2)
except ValueError:
self._has_to_destroy = 0
raise
def __init__(self, int n0=2, int n1=2, int n2=4):
self._shapeK_loc = self.get_shapeK_loc()
......@@ -31,7 +37,8 @@ cdef class ${class_name}:
self.comm = comm
def __dealloc__(self):
self.thisptr.destroy()
if self._has_to_destroy:
self.thisptr.destroy()
del self.thisptr
def get_short_name(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment