In the numerical code, running on thousands of processors for 10 s, I have a base class (Mesh) whose methods hit from 100 to 1000 milliseconds. There are currently two (Mesh_A, Mesh_B) derived classes, but this will eventually expand to three or four. Custom code cannot know until runtime whether its pointer to Mesh is actually Mesh_A or Mesh_B, but it never changes for the rest of the run.
Current implementation:
class Mesh {
...
virtual const Point& cell_centroid(int c) = 0;
}
class MeshA : public Mesh {
...
Point& cell_centroid(int c) { return cell_centroids_[c]; }
}
class MeshB : public Mesh {
...
Point& cell_centroid(int c) { return other_framework_->cell_centroid(c); }
}
class User {
User(Mesh* mesh) : mesh_(mesh) {}
void evalFunction() {
for (int c=0; c!=mesh_->num_cells(); ++c) {
double result = func(mesh_->cell_centroid(c));
...
}
}
}
MeshA , , . , (, - ?) ~ 15%, .
, , .
1: , . , " " , , . , Mesh, , cell_centroid() .
class Mesh {
...
virtual void evalFunction(double (*func)(Point&), std::vector<double>* result) = 0;
}
class MeshA : public Mesh {
...
void evalFunction(double (*func)(Point&), std::vector<double>* result) {
for (int c=0; c!=num_cells(); ++c) (*result)[c] = (*func)(cell_centroid(c));
}
Point& cell_centroid(int c) { return cell_centroids_[c]; }
}
class User {
User(Mesh* mesh) : mesh_(mesh) {}
void evalFunction() {
m_->evalFunction();
}
}
, Mesh - (, ), . , Mesh (15-20) 3 4 " ", Mesh . "", , Mesh , , .
2: Mesh_T. factory, User<MeshA> User<MeshB> . , , - , , .. .
3: , , Mesh MeshA MeshB, A B. , , Idea 1, User case/switch. , .
, !