Commit 4759cbc2 by xiaotong

updates of XNNRecord

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