Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support runtime choice of precision #1549

Closed
stevengj opened this issue Apr 14, 2021 · 5 comments
Closed

support runtime choice of precision #1549

stevengj opened this issue Apr 14, 2021 · 5 comments
Assignees

Comments

@stevengj
Copy link
Collaborator

As commented in #1544, it would be good to be able to switch precision at runtime, by making fields<T>, fields_chunk<T>, structure<T>, and structure_chunk<T> template classes parameterized by the realnum type T.

@oskooi oskooi self-assigned this Apr 14, 2021
@oskooi
Copy link
Collaborator

oskooi commented Apr 18, 2021

I have started working on this by first going through meep.hpp and templating any class which currently includes a realnum type or contains a member function which calls/uses a templated class. The problem is the sheer number of changes that are necessary. Apart from templating the classes fields, fields_chunk, structure, and structure_chunk, there are also other classes susceptibility, boundary_region, flux_vol, etc, that are also templated. Next I would need to template the definitions of all the member functions of these classes which are scattered across numerous files. This is not a straightforward task given the dependencies among the various classes/functions. It will take some time to set this up correctly.

A more practical alternative is to keep the current compile-time option and just enable single precision by default. All we would then need to do is modify the unit tests so that everything passes.

@oskooi
Copy link
Collaborator

oskooi commented Apr 18, 2021

Another complication to adding templates are two existing typedefs in meep.hpp which cannot be templated but which involve parameters that are templated classes susceptibility and fields_chunk:

meep/src/meep.hpp

Lines 1318 to 1323 in 2dcfa9f

// data for each susceptibility
typedef struct polarization_state_s {
void *data; // internal polarization data for the susceptibility
const susceptibility *s;
struct polarization_state_s *next; // linked list
} polarization_state;

meep/src/meep.hpp

Lines 1476 to 1479 in 2dcfa9f

typedef void (*field_chunkloop)(fields_chunk *fc, int ichunk, component cgrid, ivec is, ivec ie,
vec s0, vec s1, vec e0, vec e1, double dV0, double dV1, ivec shift,
std::complex<double> shift_phase, const symmetry &S, int sn,
void *chunkloop_data);

The issue here is that a fair amount of code reorganization (not directly related to templating) is required to set this all up.

@stevengj
Copy link
Collaborator Author

I think that any competent C++ programmer should be able to do this — it doesn't require any particular knowledge of how Meep works, and is just a (tedious but straightforward) matter of changing a type in one place and then tracing how that change propagates through the library, which is a common software-engineering task.

@stevengj
Copy link
Collaborator Author

stevengj commented Jun 1, 2021

As an alternative, when you build with --enable-single, it could just rename the files when it installs from meep to meep_single.

@oskooi
Copy link
Collaborator

oskooi commented Oct 3, 2021

Replaced by #1544, #1563, #1688, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants