Commit 4759cbc2 by xiaotong

updates of XNNRecord

parent 968c1e92
......@@ -306,7 +306,7 @@ bool XLeader::Run(XConfig * config, DataDistributeBase * dataDistributor,
worker->GetGold(), worker->GetLoss());
/* job in queue 1: make a record of the run */
worker->AddJobRecord();
worker->AddJobRecord(&serverRecord);
active[i] = 1;
activeJobCount++;
......
......@@ -34,11 +34,13 @@ namespace nts { // namespace nts(NiuTrans.Tensor)
XNNRecord::XNNRecord()
{
Clear();
MUTEX_INIT(mutex);
}
/* de-constructor */
XNNRecord::~XNNRecord()
{
MUTEX_DELE(mutex);
}
/* clear it */
......
......@@ -49,6 +49,9 @@ public:
/* state */
XWORKER_STATE state;
/* mutex */
MUTEX_HANDLE mutex;
public:
/* constructor */
XNNRecord();
......
......@@ -230,20 +230,6 @@ bool XWorkerJob::AddJobNeuralNet(XModel * myModel,
return true;
}
/* add a new job of recording the running of the nerual network */
bool XWorkerJob::AddJobRecord()
{
XList args;
args.Add(this);
if (isInstantRun)
XWorkerJob::RecordMeStatic(&args);
else
queue.EnqueueJob((void*)(char*)XWorkerJob::RecordMeStatic, &args);
return true;
}
/* wrapper of RecordMe */
void XWorkerJob::RecordMeStatic(XList* args)
{
......@@ -252,13 +238,37 @@ void XWorkerJob::RecordMeStatic(XList* args)
CheckNTErrors(args != NULL && args->count > 0, "Illegal arguments!");
XWorkerJob * worker = (XWorkerJob*)args->GetItem(0);
XNNRecord * serverRecord = (XNNRecord *)args->GetItem(1);
worker->RecordMe();
/* push information to the server end */
MUTEX_LOCK(serverRecord->mutex);
serverRecord->Update(*worker->GetRecord());
MUTEX_UNLOCK(serverRecord->mutex);
worker->SetState(XWORKER_FINISHED);
//fprintf(stderr, "record static 1\n");
}
/*
add a new job of recording the running of the nerual network
>>
*/
bool XWorkerJob::AddJobRecord(XNNRecord * serverRecord)
{
XList args;
args.Add(this);
args.Add(serverRecord);
if (isInstantRun)
XWorkerJob::RecordMeStatic(&args);
else
queue.EnqueueJob((void*)(char*)XWorkerJob::RecordMeStatic, &args);
return true;
}
} /* end of the nts (NiuTrans.Tensor) namespace */
......@@ -113,7 +113,7 @@ public:
bool AddJobNeuralNet(XModel * myModel, XList * inputs, XList * outputs, XList * golds, XList * losses);
/* add a new job of recording the running of the nerual network */
bool AddJobRecord();
bool AddJobRecord(XNNRecord * serverRecord);
private:
/* wrapper of RecordMe */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论