Skip to content

Commit

Permalink
used time profiler in interface form
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Jan 15, 2025
1 parent 8be9eaa commit e36deb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
5 changes: 1 addition & 4 deletions include/interface_form.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ namespace mfem
class InterfaceForm
{
private:
static const int Ntimer = 6;
mutable StopWatch *timers[Ntimer];
mutable int topol_call = 0;
mutable int assemble_call = 0;
mutable TimeProfiler timer;

protected:
int numSub = -1;
Expand Down
52 changes: 16 additions & 36 deletions src/interface_form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace mfem

InterfaceForm::InterfaceForm(
Array<Mesh *> &meshes_, Array<FiniteElementSpace *> &fes_, TopologyHandler *topol_)
: meshes(meshes_), fes(fes_), topol_handler(topol_), numSub(meshes_.Size()), topol_call(0), assemble_call(0)
: meshes(meshes_), fes(fes_), topol_handler(topol_), numSub(meshes_.Size()), timer()
{
assert(fes_.Size() == numSub);

Expand All @@ -21,31 +21,13 @@ InterfaceForm::InterfaceForm(
for (int i = 1; i < numSub + 1; i++)
block_offsets[i] = fes[i-1]->GetTrueVSize();
block_offsets.PartialSum();

for (int k = 0; k < Ntimer; k++)
timers[k] = new StopWatch;
}

InterfaceForm::~InterfaceForm()
{
DeletePointers(fnfi);

printf("InterfaceForm::InterfaceAddMult\n");
printf("topol call: %d\n", topol_call);
printf("assemble call: %d\n", assemble_call);
printf("%10s\t%10s\t%10s\t%10s\t%10s\t%10s\t%10s\n",
"init", "port-init", "topol", "assemble", "final", "sum", "total");
double sum = 0.0;
for (int k = 0; k < Ntimer-1; k++)
{
printf("%.3E\t", timers[k]->RealTime());
sum += timers[k]->RealTime();
}
printf("%.3E\t", sum);
printf("%.3E\n", timers[Ntimer-1]->RealTime());

for (int k = 0; k < Ntimer; k++)
delete timers[k];
timer.Print("InterfaceForm::InterfaceAddMult");
}

void InterfaceForm::AssembleInterfaceMatrices(Array2D<SparseMatrix *> &mats) const
Expand Down Expand Up @@ -85,9 +67,8 @@ void InterfaceForm::AssembleInterfaceMatrices(Array2D<SparseMatrix *> &mats) con

void InterfaceForm::InterfaceAddMult(const Vector &x, Vector &y) const
{
printf("InterfaceForm::InterfaceAddMult\n");
timers[5]->Start();
timers[0]->Start();
timer.Start("Total");
timer.Start("init");

x_tmp.Update(const_cast<Vector&>(x), block_offsets);
y_tmp.Update(y, block_offsets);
Expand All @@ -96,11 +77,11 @@ printf("InterfaceForm::InterfaceAddMult\n");
Mesh *mesh1, *mesh2;
FiniteElementSpace *fes1, *fes2;

timers[0]->Stop();
timer.Stop("init");

for (int p = 0; p < topol_handler->GetNumPorts(); p++)
{
timers[1]->Start();
timer.Start("port-init");

const PortInfo *pInfo = topol_handler->GetPortInfo(p);

Expand All @@ -115,21 +96,20 @@ printf("InterfaceForm::InterfaceAddMult\n");

Array<InterfaceInfo>* const interface_infos = topol_handler->GetInterfaceInfos(p);

timers[1]->Stop();
timer.Stop("port-init");

AssembleInterfaceVector(mesh1, mesh2, fes1, fes2, interface_infos,
x_tmp.GetBlock(midx[0]), x_tmp.GetBlock(midx[1]),
y_tmp.GetBlock(midx[0]), y_tmp.GetBlock(midx[1]));
} // for (int p = 0; p < topol_handler->GetNumPorts(); p++)

timers[4]->Start();
timer.Start("final");

for (int i=0; i < y_tmp.NumBlocks(); ++i)
y_tmp.GetBlock(i).SyncAliasMemory(y);

timers[4]->Stop();

timers[5]->Stop();
timer.Stop("final");
timer.Stop("Total");
}

void InterfaceForm::InterfaceGetGradient(const Vector &x, Array2D<SparseMatrix *> &mats) const
Expand Down Expand Up @@ -274,16 +254,15 @@ void InterfaceForm::AssembleInterfaceVector(Mesh *mesh1, Mesh *mesh2,

for (int bn = 0; bn < interface_infos->Size(); bn++)
{
timers[2]->Start();
timer.Start("topol");

InterfaceInfo *if_info = &((*interface_infos)[bn]);

topol_handler->GetInterfaceTransformations(mesh1, mesh2, if_info, tr1, tr2);
topol_call++;

timers[2]->Stop();
timer.Stop("topol");

timers[3]->Start();
timer.Start("assemble");

if ((tr1 != NULL) && (tr2 != NULL))
{
Expand All @@ -301,15 +280,16 @@ void InterfaceForm::AssembleInterfaceVector(Mesh *mesh1, Mesh *mesh2,
{
assert(fnfi[itg]);

timer.Start("assemble-itf-vec");
fnfi[itg]->AssembleInterfaceVector(*fe1, *fe2, *tr1, *tr2, el_x1, el_x2, el_y1, el_y2);
assemble_call += fnfi[itg]->GetIntegrationRule()->GetNPoints();
timer.Stop("assemble-itf-vec");

y1.AddElementVector(vdofs1, el_y1);
y2.AddElementVector(vdofs2, el_y2);
}
} // if ((tr1 != NULL) && (tr2 != NULL))

timers[3]->Stop();
timer.Stop("assemble");
} // for (int bn = 0; bn < interface_infos.Size(); bn++)
}

Expand Down

0 comments on commit e36deb0

Please sign in to comment.