MatlabCreator speed up.
This commit is contained in:
@@ -22,14 +22,27 @@
|
|||||||
#include "Parser.h"
|
#include "Parser.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
struct CreateMatSturct
|
||||||
|
{
|
||||||
|
std::shared_ptr<Parser> mParser;
|
||||||
|
std::string mFileName;
|
||||||
|
std::shared_ptr<short> mAScanData;
|
||||||
|
std::shared_ptr<double> mAmplificationData;
|
||||||
|
};
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
|
|
||||||
|
std::queue<CreateMatSturct> PRODUCER_DATAS;
|
||||||
|
std::mutex PRODUCER_MUTEX;
|
||||||
|
std::condition_variable PRODUCER_CONDITION;
|
||||||
|
|
||||||
std::string getTasFolderName(unsigned short aNum)
|
std::string getTasFolderName(unsigned short aNum)
|
||||||
{
|
{
|
||||||
if (aNum < 10)
|
if (aNum < 10)
|
||||||
@@ -143,6 +156,48 @@ bool MatlabCreatorPrivate::createKITMat(const std::string& aOutputPath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MatlabCreatorPrivate::createKITMatInThread(std::shared_ptr<Parser> aParser, unsigned short aStartTasNum,unsigned short aTasCount, const std::string& aOutputPath)
|
void MatlabCreatorPrivate::createKITMatInThread(std::shared_ptr<Parser> aParser, unsigned short aStartTasNum,unsigned short aTasCount, const std::string& aOutputPath)
|
||||||
|
{
|
||||||
|
std::thread producerThread = std::thread(&MatlabCreatorPrivate::producerThreadFunction, this, aParser, aStartTasNum, aTasCount, aOutputPath);
|
||||||
|
ShotList* shotList = aParser->getShotList().get();
|
||||||
|
for(unsigned short t=aStartTasNum;t<aStartTasNum+aTasCount;++t)
|
||||||
|
{
|
||||||
|
//Motorposition
|
||||||
|
for(unsigned short m=0;m<shotList->getMotorPositionSize();++m)
|
||||||
|
{
|
||||||
|
for(unsigned short e=0;e<shotList->getElementSize();++e)
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(PRODUCER_MUTEX);
|
||||||
|
PRODUCER_CONDITION.wait(lock, []{return !PRODUCER_DATAS.empty();});
|
||||||
|
std::shared_ptr<Parser> parser = PRODUCER_DATAS.front().mParser;
|
||||||
|
std::string fileName = PRODUCER_DATAS.front().mFileName;
|
||||||
|
std::shared_ptr<short> ascanData = PRODUCER_DATAS.front().mAScanData;
|
||||||
|
std::shared_ptr<double> amplificationData = PRODUCER_DATAS.front().mAmplificationData;
|
||||||
|
PRODUCER_DATAS.pop();
|
||||||
|
lock.unlock();
|
||||||
|
createEmitterMat(parser,fileName,ascanData,amplificationData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//CEMeasure
|
||||||
|
if(shotList->hasCEMeasured())
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(PRODUCER_MUTEX);
|
||||||
|
PRODUCER_CONDITION.wait(lock, []{return !PRODUCER_DATAS.empty();});
|
||||||
|
std::shared_ptr<Parser> parser = PRODUCER_DATAS.front().mParser;
|
||||||
|
std::string fileName = PRODUCER_DATAS.front().mFileName;
|
||||||
|
std::shared_ptr<short> ascanData = PRODUCER_DATAS.front().mAScanData;
|
||||||
|
std::shared_ptr<double> amplificationData = PRODUCER_DATAS.front().mAmplificationData;
|
||||||
|
PRODUCER_DATAS.pop();
|
||||||
|
lock.unlock();
|
||||||
|
createEmitterMat(parser,fileName,ascanData,amplificationData);
|
||||||
|
}
|
||||||
|
++progress;
|
||||||
|
std::cout<<"\r\033[K"<<std::flush;
|
||||||
|
std::cout<< "progress: \033[41m\033[1m " + std::to_string(progress/1.28) + "%\033[0m" <<std::flush;
|
||||||
|
}
|
||||||
|
producerThread.join();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MatlabCreatorPrivate::producerThreadFunction(std::shared_ptr<Parser> aParser, unsigned short aStartTasNum,unsigned short aTasCount, const std::string& aOutputPath)
|
||||||
{
|
{
|
||||||
std::string dirPath = aOutputPath;
|
std::string dirPath = aOutputPath;
|
||||||
DirHelper dir;
|
DirHelper dir;
|
||||||
@@ -170,7 +225,11 @@ void MatlabCreatorPrivate::createKITMatInThread(std::shared_ptr<Parser> aParser,
|
|||||||
std::shared_ptr<double> amplificationData = std::shared_ptr<double>(new double[aParser->getDataLength()*RECEIVE_ELEMENT_COUNT],std::default_delete<double[]>());
|
std::shared_ptr<double> amplificationData = std::shared_ptr<double>(new double[aParser->getDataLength()*RECEIVE_ELEMENT_COUNT],std::default_delete<double[]>());
|
||||||
getAScanOfMPAndAmplification(aParser,shotList,oneTasAscan,ascanData,amplificationData,element,MotorPosition(shotList->getMotorPositionValue(m)));
|
getAScanOfMPAndAmplification(aParser,shotList,oneTasAscan,ascanData,amplificationData,element,MotorPosition(shotList->getMotorPositionValue(m)));
|
||||||
std::string fileName = motorpositionFolder + SLASH_CHAR + getMatFileName(element);
|
std::string fileName = motorpositionFolder + SLASH_CHAR + getMatFileName(element);
|
||||||
createEmitterMat(aParser,fileName,ascanData,amplificationData);
|
std::unique_lock<std::mutex> lock(PRODUCER_MUTEX);
|
||||||
|
PRODUCER_DATAS.push({aParser,fileName,ascanData,amplificationData});
|
||||||
|
lock.unlock();
|
||||||
|
PRODUCER_CONDITION.notify_one();
|
||||||
|
//createEmitterMat(aParser,fileName,ascanData,amplificationData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//CEMeasure
|
//CEMeasure
|
||||||
@@ -186,11 +245,12 @@ void MatlabCreatorPrivate::createKITMatInThread(std::shared_ptr<Parser> aParser,
|
|||||||
std::shared_ptr<double> amplificationData = std::shared_ptr<double>(new double[aParser->getDataLength()*RECEIVE_ELEMENT_COUNT],std::default_delete<double[]>());
|
std::shared_ptr<double> amplificationData = std::shared_ptr<double>(new double[aParser->getDataLength()*RECEIVE_ELEMENT_COUNT],std::default_delete<double[]>());
|
||||||
getAScanOfCEAndAmplification(aParser,shotList,oneTasAscan,ascanData,amplificationData);
|
getAScanOfCEAndAmplification(aParser,shotList,oneTasAscan,ascanData,amplificationData);
|
||||||
std::string fileName = cemeasureFolder + SLASH_CHAR + getMatFileName(0);
|
std::string fileName = cemeasureFolder + SLASH_CHAR + getMatFileName(0);
|
||||||
createEmitterMat(aParser,fileName,ascanData,amplificationData);
|
std::unique_lock<std::mutex> lock(PRODUCER_MUTEX);
|
||||||
|
PRODUCER_DATAS.push({aParser,fileName,ascanData,amplificationData});
|
||||||
|
lock.unlock();
|
||||||
|
PRODUCER_CONDITION.notify_one();
|
||||||
|
//createEmitterMat(aParser,fileName,ascanData,amplificationData);
|
||||||
}
|
}
|
||||||
++progress;
|
|
||||||
std::cout<<"\r\033[K"<<std::flush;
|
|
||||||
std::cout<< "progress: \033[41m\033[1m " + std::to_string(progress/1.28) + "%\033[0m" <<std::flush;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,10 +308,7 @@ void MatlabCreatorPrivate::getAScanOfCEAndAmplification(std::shared_ptr<Parser>
|
|||||||
unsigned short receiveElement = mapperArrayPointer.get()[index + 2 + aShotList->getMuxValue(muxIndex)];
|
unsigned short receiveElement = mapperArrayPointer.get()[index + 2 + aShotList->getMuxValue(muxIndex)];
|
||||||
AScanData ascan = aParser->searchAscanDataFromOneTasAscanDataOfCE(aOneTasAScanData,TasElementIndex(TasIndex(receiveTas),ElementIndex(GeometryIndex(receiveElement))));
|
AScanData ascan = aParser->searchAscanDataFromOneTasAscanDataOfCE(aOneTasAScanData,TasElementIndex(TasIndex(receiveTas),ElementIndex(GeometryIndex(receiveElement))));
|
||||||
aAmplificationData.get()[muxIndex*TOTAL_CHANNEL+i] = ascan.getAmplification()[0];
|
aAmplificationData.get()[muxIndex*TOTAL_CHANNEL+i] = ascan.getAmplification()[0];
|
||||||
for(unsigned short j=0;j<aParser->getDataLength();++j)
|
std::copy(ascan.get(), ascan.get() + aParser->getDataLength(), aAScanData.get() + (muxIndex*TOTAL_CHANNEL+i)*aParser->getDataLength());
|
||||||
{
|
|
||||||
aAScanData.get()[(muxIndex*TOTAL_CHANNEL+i)*aParser->getDataLength()+j] = ascan.get()[j];
|
|
||||||
}
|
|
||||||
index+=9;
|
index+=9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,10 +326,7 @@ void MatlabCreatorPrivate::getAScanOfMPAndAmplification(std::shared_ptr<Parser>
|
|||||||
unsigned short receiveElement = mapperArrayPointer.get()[index + 2 + aShotList->getMuxValue(muxIndex)];
|
unsigned short receiveElement = mapperArrayPointer.get()[index + 2 + aShotList->getMuxValue(muxIndex)];
|
||||||
AScanData ascan = aParser->searchAscanDataFromOneTasAscanDataOfMP(aOneTasAScanData,ElementIndex(GeometryIndex(aGeometryElement)),TasElementIndex(TasIndex(receiveTas),ElementIndex(GeometryIndex(receiveElement))),aMotorPosition);
|
AScanData ascan = aParser->searchAscanDataFromOneTasAscanDataOfMP(aOneTasAScanData,ElementIndex(GeometryIndex(aGeometryElement)),TasElementIndex(TasIndex(receiveTas),ElementIndex(GeometryIndex(receiveElement))),aMotorPosition);
|
||||||
aAmplificationData.get()[muxIndex*TOTAL_CHANNEL+i] = ascan.getAmplification()[0];
|
aAmplificationData.get()[muxIndex*TOTAL_CHANNEL+i] = ascan.getAmplification()[0];
|
||||||
for(unsigned short j=0;j<aParser->getDataLength();++j)
|
std::copy(ascan.get(), ascan.get() + aParser->getDataLength(), aAScanData.get() + (muxIndex*TOTAL_CHANNEL+i)*aParser->getDataLength());
|
||||||
{
|
|
||||||
aAScanData.get()[(muxIndex*TOTAL_CHANNEL+i)*aParser->getDataLength()+j] = ascan.get()[j];
|
|
||||||
}
|
|
||||||
index+=9;
|
index+=9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ private:
|
|||||||
void createMeasurementRotationMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
void createMeasurementRotationMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
||||||
void createMovementsMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
void createMovementsMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
||||||
void createPatDataMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
void createPatDataMat(std::shared_ptr<Parser> aParser, const std::string& aDirectoryPath);
|
||||||
|
void producerThreadFunction(std::shared_ptr<Parser> aParser, unsigned short aStartTasNum,unsigned short aTasCount, const std::string& aOutputPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mDirectoryPath;
|
std::string mDirectoryPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user