I have the following code for matrix-vector multiplication:
std::chrono::steady_clock::time_point start, end2;
void fillMatrixConditions(LPVOID lpv) {
end2 = std::chrono::steady_clock::now();
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end2 - start).count() << std::endl;
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::nanoseconds> (end2 - start).count() << std::endl;
int i, j = horizontControl;
for (i = 0; i < horizontControl; i++, j++) {
b[i] = akcni - uMin;
b[j] = uMax - akcni;
}
j = 2 * horizontControl + N - N1 + 1;
int k = 0;
for (i = 2 * i; i < (2 * horizontControl + N - N1 + 1); i++, j++, k++) {
b[i] = MpDup[k] - yMin;
b[j] = yMax - MpDup[k];
};
RtPrintf("Thread");
}
int _tmain(int argc, _TCHAR * argv[])
{
HANDLE hThread;
DWORD id;
int k = 0;
double temp;
double g[50];
for (int j = 0; j < N - N1 + 1; j++)
{
temp = 0;
for (int m = 0; m < horizontPrediction - 1; m++, k++)
{
temp = temp + Mp[k] * dup[m];
}
MpDup[j] = temp;
tempMatrix[j] = setPoint - y - temp;
}
start = std::chrono::steady_clock::now();
hThread = CreateThread(NULL, NULL, (LPTHREAD_START_ROUTINE)fillMatrixConditions, NULL, NULL, &id);
k = 0;
for (int j = 0; j < horizontControl; j++)
{
temp = 0;
for (int m = 0; m < N - N1 + 1; m++, k++)
{
temp = temp + Mtranspose[k] * tempMatrix[m];
}
g[j] = -2 * temp;
}
RtPrintf("Point\n");
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
return 0;
}
But CreateThread()
is too slow, because this is the output of the program:
Point
Time difference = 247
Time difference = 247261
I thought the first thing to be written was going to be the Time difference
in thread and then "Point". Or is this output normal? I must use CreateThread()
. I can't pthread
etc. Matrix Mtranspose
has 2025
cells.