NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.22k stars 621 forks source link

Using single precision for large arrays #887

Closed houge9089 closed 5 years ago

houge9089 commented 5 years ago

I'd like to use single precision in time stepping and fourier transforming. Before installing, I modified #define MEEP_SINGLE 0 as #define MEEP_SINGLE 1 in meep.hpp. Then, some errors occured while installing:

CXX anisotropic_averaging.lo CXX bands.lo CXX boundaries.lo CXX bicgstab.lo CXX casimir.lo CXX control_c.lo CXX cw_fields.lo CXX dft.lo dft.cpp: In member function ‘cdouble meep::dft_chunk::process_dft_component(int, meep::direction, meep::ivec, meep::ivec, int, meep::h5file, double, int, cdouble, void, void, int, bool, meep::fields)’: dft.cpp:762:81: error: no match for ‘operator/’ (operand types are ‘std::complex’ and ‘std::complex’) : dft[Nomega (chunk_idx++) + num_freq] / stored_weight); ^ In file included from meep/vec.hpp:22:0, from meep.hpp:24, from dft.cpp:24: /usr/include/c++/5/complex:416:5: note: candidate: template std::complex<_Tp> std::operator/(const std::complex<_Tp>&, const std::complex<_Tp>&) operator/(const complex<_Tp>& x, const complex<_Tp>& __y) ^ /usr/include/c++/5/complex:416:5: note: template argument deduction/substitution failed: dft.cpp:762:83: note: deduced conflicting types for parameter ‘_Tp’ (‘float’ and ‘double’) : dft[Nomega * (chunk_idx++) + num_freq] / stored_weight); ^ In file included from meep/vec.hpp:22:0, from meep.hpp:24, from dft.cpp:24: /usr/include/c++/5/complex:425:5: note: candidate: template std::complex<_Tp> std::operator/(const std::complex<_Tp>&, const _Tp&) operator/(const complex<_Tp>& x, const _Tp& y) ^ /usr/include/c++/5/complex:425:5: note: template argument deduction/substitution failed: dft.cpp:762:83: note: deduced conflicting types for parameter ‘const _Tp’ (‘float’ and ‘std::complex’) : dft[Nomega * (chunk_idx++) + num_freq] / stored_weight); ^ In file included from meep/vec.hpp:22:0, from meep.hpp:24, from dft.cpp:24: /usr/include/c++/5/complex:434:5: note: candidate: template std::complex<_Tp> std::operator/(const _Tp&, const std::complex<_Tp>&) operator/(const _Tp& __x, const complex<_Tp>& y) ^ /usr/include/c++/5/complex:434:5: note: template argument deduction/substitution failed: dft.cpp:762:83: note: deduced conflicting types for parameter ‘_Tp’ (‘std::complex’ and ‘double’) : dft[Nomega (chunk_idx++) + num_freq] / stored_weight); ^ dft.cpp:802:62: error: no matching function for call to ‘meep::h5file::write_chunk(int&, size_t [3], size_t [3], double&)’ if (file) file->write_chunk(rank, start, file_count, buffer); ^ In file included from dft.cpp:24:0: meep.hpp:349:8: note: candidate: void meep::h5file::write_chunk(int, const size_t, const size_t, meep::realnum) void write_chunk(int rank, const size_t chunk_start, const size_t chunk_dims, realnum data); ^ meep.hpp:349:8: note: no known conversion for argument 4 from ‘double’ to ‘meep::realnum {aka float}’ meep.hpp:350:8: note: candidate: void meep::h5file::write_chunk(int, const size_t, const size_t, size_t) void write_chunk(int rank, const size_t chunk_start, const size_t chunk_dims, size_t data); ^ meep.hpp:350:8: note: no known conversion for argument 4 from ‘double’ to ‘size_t {aka long unsigned int}’ dft.cpp: In member function ‘cdouble meep::fields::process_dft_component(meep::dft_chunk, int, int, meep::component, const char*, cdouble*, int, size_t, meep::direction, void, void, meep::component, bool, bool)’: dft.cpp:946:92: error: no matching function for call to ‘meep::dft_chunk::process_dft_component(int&, meep::direction [3], meep::ivec&, meep::ivec&, int&, meep::h5file&, meep::realnum&, int&, cdouble&, void&, void&, int&, bool&, meep::fields)’ ic_conjugate, retain_interp_weights, this); ^ dft.cpp:687:9: note: candidate: cdouble meep::dft_chunk::process_dft_component(int, meep::direction, meep::ivec, meep::ivec, int, meep::h5file, double, int, cdouble, void, void, int, bool, meep::fields) cdouble dft_chunk::process_dft_component(int rank, direction ds, ivec min_corner, ivec max_corner, ^ dft.cpp:687:9: note: no known conversion for argument 7 from ‘meep::realnum {aka float}’ to ‘double’ dft.cpp: In member function ‘void meep::fields::output_dft_components(meep::dft_chunk, int, meep::volume, const char)’: dft.cpp:1085:75: error: no matching function for call to ‘meep::h5file::write(char [100], int&, size_t [3], double&, bool&)’ file->write(dataname, rank, dims, real_array, single_precision); ^ In file included from dft.cpp:24:0: meep.hpp:338:8: note: candidate: void meep::h5file::write(const char, int, const size_t, meep::realnum, bool) void write(const char dataname, int rank, const size_t dims, realnum data, ^ meep.hpp:338:8: note: no known conversion for argument 4 from ‘double’ to ‘meep::realnum {aka float}’ meep.hpp:342:8: note: candidate: void meep::h5file::write(const char, const char) void write(const char dataname, const char *data); ^ meep.hpp:342:8: note: candidate expects 2 arguments, 5 provided Makefile:626: recipe for target 'dft.lo' failed make[4]: [dft.lo] Error 1 make[4]: Leaving directory '/root/install/meep/src' Makefile:687: recipe for target 'all-recursive' failed make[3]: [all-recursive] Error 1 make[3]: Leaving directory '/root/install/meep/src' Makefile:478: recipe for target 'all' failed make[2]: [all] Error 2 make[2]: Leaving directory '/root/install/meep/src' Makefile:505: recipe for target 'all-recursive' failed make[1]: [all-recursive] Error 1 make[1]: Leaving directory '/root/install/meep' Makefile:414: recipe for target 'all' failed make: *** [all] Error 2

Are there any methods to use meep python (or c++) in single precision iterations?

stevengj commented 5 years ago

Yes, single-precision support hasn't been tested for a while, so I'm not surprised it has bitrotted. Shouldn't be too hard to get it working again.

(The fact that std::complex<double> doesn't support mixed-precision operations has always been a big pain.)