Commit ad43b9b9 authored by Ansgar Burchardt's avatar Ansgar Burchardt

Merge branch '42-shared-library-issues' into 'master'

fix issues when building dune-uggrid as shared library

Closes #42

See merge request !113
parents 4f0ceccd 9fbbdf06
......@@ -30,9 +30,9 @@ struct LowCommContext
struct NotifyContext
{
NOTIFY_INFO* allInfoBuffer;
NOTIFY_DESC* theDescs;
int* theRouting;
std::vector<NOTIFY_INFO> allInfoBuffer;
std::vector<NOTIFY_DESC> theDescs;
std::vector<int> theRouting;
int maxInfos;
int lastInfo;
int nSendDescs;
......@@ -40,8 +40,8 @@ struct NotifyContext
struct TopoContext
{
PPIF::VChannelPtr* theTopology;
DDD_PROC* theProcArray;
std::vector<PPIF::VChannelPtr> theTopology;
std::vector<DDD_PROC> theProcArray;
};
} /* namespace Basic */
......
......@@ -181,6 +181,30 @@ struct TYPE_DESC
std::unique_ptr<unsigned char[]> cmask;
};
namespace Basic {
struct NOTIFY_DESC
{
DDD_PROC proc;
size_t size;
};
enum class NotifyTypes : unsigned short
{
MYSELF,
KNOWN,
DUMMY,
UNKNOWN
};
struct NOTIFY_INFO {
short from, to; /* source and destination processor */
NotifyTypes flag; /* one of NotifyTypes */
size_t size; /* message size */
};
} /* namespace Basic */
namespace If {
using IFObjPtr = DDD_OBJ;
......
......@@ -15,10 +15,11 @@ dune_add_library(ugL $<TARGET_OBJECTS:devices> $<TARGET_OBJECTS:low> ${_parallel
SOURCES
../dune/uggrid/parallel/ddd/dddcontext.cc
../dune/uggrid/parallel/ppif/ppifcontext.cc
ADD_LIBS ${DUNE_LIBS}
)
ug_add_dim_libs(ugS APPEND DUNE SOURCES ../initug.cc
OBJECT_DIM_LIBS ${_dim_libs} domS ${_parallel_dim_libs}
ADD_LIBS ugL
ADD_LIBS ugL ${DUNE_LIBS}
)
if(MPI_C_FOUND)
......
......@@ -54,28 +54,8 @@ using namespace PPIF;
#define DebugNotify 10 /* 0 is all, 10 is off */
/****************************************************************************/
/* */
/* data structures */
/* */
/****************************************************************************/
namespace DDD {
namespace Basic {
enum NotifyTypes {MYSELF,KNOWN,DUMMY,UNKNOWN};
struct NOTIFY_INFO {
short from, to; /* source and destination processor */
unsigned short flag; /* one of NotifyTypes */
size_t size; /* message size */
};
#define PROC_INVALID_TEMP -1
} /* namespace Basic */
} /* namespace DDD */
/****************************************************************************/
/* */
/* routines */
......@@ -97,29 +77,15 @@ void NotifyInit(DDD::DDDContext& context)
const auto procs = context.procs();
/* allocate memory */
ctx.theRouting = (int *) AllocFix(procs*sizeof(int));
if (ctx.theRouting == nullptr)
throw std::bad_alloc();
ctx.theRouting.resize(procs);
ctx.maxInfos = MAX_INFOS(procs); /* TODO maximum value, just for testing */
/* init local array for all Info records */
ctx.allInfoBuffer = (NOTIFY_INFO *) AllocFix(ctx.maxInfos*sizeof(NOTIFY_INFO));
if (ctx.allInfoBuffer == nullptr)
throw std::bad_alloc();
ctx.allInfoBuffer.resize(ctx.maxInfos);
/* allocate array of NOTIFY_DESCs */
if (procs>1)
{
ctx.theDescs = (NOTIFY_DESC *) AllocTmp(sizeof(NOTIFY_DESC)*(procs-1));
}
else
{
ctx.theDescs = nullptr;
}
ctx.theDescs.resize(procs-1);
}
......@@ -128,13 +94,9 @@ void NotifyExit(DDD::DDDContext& context)
auto& ctx = context.notifyContext();
/* free memory */
FreeFix(ctx.theRouting);
FreeFix(ctx.allInfoBuffer);
if (ctx.theDescs != nullptr)
{
FreeTmp(ctx.theDescs,sizeof(NOTIFY_DESC)*(context.procs()-1));
}
ctx.theRouting.clear();
ctx.allInfoBuffer.clear();
ctx.theDescs.clear();
}
......@@ -162,7 +124,7 @@ NOTIFY_INFO *NotifyPrepare (DDD::DDDContext& context)
#endif
/* init local array for all Info records */
NOTIFY_INFO* allInfos = ctx.allInfoBuffer;
NOTIFY_INFO* allInfos = ctx.allInfoBuffer.data();
/* init local routing array */
......@@ -173,7 +135,7 @@ NOTIFY_INFO *NotifyPrepare (DDD::DDDContext& context)
allInfos[0].from = me;
allInfos[0].to = PROC_INVALID_TEMP;
allInfos[0].size = 0;
allInfos[0].flag = DUMMY;
allInfos[0].flag = NotifyTypes::DUMMY;
ctx.lastInfo = 1;
return allInfos;
......@@ -255,7 +217,7 @@ int NotifyTwoWave(DDD::DDDContext& context, NOTIFY_INFO *allInfos, int lastInfo,
{
if (allInfos[j].from==allInfos[i].to)
{
allInfos[i].flag = (allInfos[i].to==me) ? MYSELF : KNOWN;
allInfos[i].flag = (allInfos[i].to==me) ? NotifyTypes::MYSELF : NotifyTypes::KNOWN;
unknownInfos--;
if (allInfos[i].to==me)
myInfos++;
......@@ -411,7 +373,7 @@ NOTIFY_DESC *DDD_NotifyBegin(DDD::DDDContext& context, int n)
return nullptr;
}
return ctx.theDescs;
return ctx.theDescs.data();
}
......@@ -471,7 +433,7 @@ int DDD_Notify(DDD::DDDContext& context)
allInfos[ctx.lastInfo].from = me;
allInfos[ctx.lastInfo].to = ctx.theDescs[i].proc;
allInfos[ctx.lastInfo].size = ctx.theDescs[i].size;
allInfos[ctx.lastInfo].flag = UNKNOWN;
allInfos[ctx.lastInfo].flag = NotifyTypes::UNKNOWN;
ctx.lastInfo++;
}
......
......@@ -34,18 +34,6 @@
#include "include/ddd.h"
namespace DDD {
namespace Basic {
struct NOTIFY_DESC
{
DDD_PROC proc;
size_t size;
};
} /* namespace Basic */
} /* namespace DDD */
namespace DDD {
/****************************************************************************/
......
......@@ -71,47 +71,31 @@ void ddd_TopoInit(DDD::DDDContext& context)
const auto procs = context.procs();
/* get one channel pointer for each partner */
ctx.theTopology = (VChannelPtr *) AllocFix(procs*sizeof(VChannelPtr));
if (ctx.theTopology == nullptr)
{
DDD_PrintError('E', 1500, STR_NOMEM " in TopoInit");
return;
}
/* initialize channel topology */
for(int i=0; i<procs; i++)
ctx.theTopology[i] = nullptr;
ctx.theTopology.assign(procs, nullptr);
/* get proc array with maxsize = 2 * number of procs */
ctx.theProcArray = (DDD_PROC *) AllocFix(2 * procs*sizeof(DDD_PROC));
if (ctx.theProcArray == nullptr)
{
DDD_PrintError('E', 1510, STR_NOMEM " in TopoInit");
return;
}
ctx.theProcArray.resize(2 * procs);
}
void ddd_TopoExit(DDD::DDDContext& context)
{
auto& ctx = context.topoContext();
const auto procs = context.procs();
FreeFix(ctx.theProcArray);
ctx.theProcArray.clear();
/* disconnect channels */
for(int i=0; i<procs; i++)
for (const auto ch : ctx.theTopology)
{
if (ctx.theTopology[i]!=NULL)
if (ch != nullptr)
{
DiscASync(context.ppifContext(), ctx.theTopology[i]);
while (InfoADisc(context.ppifContext(), ctx.theTopology[i])!=1)
DiscASync(context.ppifContext(), ch);
while (InfoADisc(context.ppifContext(), ch)!=1)
;
}
}
FreeFix(ctx.theTopology);
ctx.theTopology.clear();
}
......@@ -120,7 +104,7 @@ void ddd_TopoExit(DDD::DDDContext& context)
DDD_PROC* DDD_ProcArray(DDD::DDDContext& context)
{
return context.topoContext().theProcArray;
return context.topoContext().theProcArray.data();
}
......
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