多线程randsim

This commit is contained in:
zzh 2023-10-07 04:26:11 +08:00
parent c9393a54e3
commit 18a5415e59
1 changed files with 6 additions and 6 deletions

View File

@ -240,8 +240,8 @@ void ThreadRandSim(TPRandSim& param) {
vr
*/
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, mxArray** prhs) {
//void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
//void mexFunction(int nlhs, mxArray* plhs[], int nrhs, mxArray** prhs) {
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
if (nrhs < 1) {
cout << "At least 3 arguments should be given for this function!" << endl;
return;
@ -326,14 +326,14 @@ void mexFunction(int nlhs, mxArray* plhs[], int nrhs, mxArray** prhs) {
}
}
//ThreadPool thPool(numThread);
ThreadPool thPool(numThread);
int tid = 0;
for (int i = 0; i < loopNum; ++i) {
TPRandSim tParam = { &vvZr[i], &vvRandPos[tid++ % numThread], &umWordPos, &vvWd2, vvWd.size()};
//thPool.enqueue(ThreadRandSim, tParam);
ThreadRandSim(tParam);
thPool.enqueue(ThreadRandSim, tParam);
//ThreadRandSim(tParam);
}
//thPool.~ThreadPool();
thPool.~ThreadPool();
finish = clock();
cout << "Random simulation time: " << (double)(finish - mid) / CLOCKS_PER_SEC << " s" << endl;