//#include<Windows.h> #include<stdio.h> #include<math.h> using namespace std; #define MAX_THREADS 20 DWORD N; DWORD Array_A[MAX_THREADS][MAX_THREADS]; DWORD Array_B[MAX_THREADS][MAX_THREADS]; DWORD MultipleArray[MAX_THREADS][MAX_THREADS]; void Print() { printf("Result:"); for (int i = 0; i < N; i++) { printf("\n"); for (int j = 0; j < N; j++) printf("%d ",MultipleArray[i][j]); } } /**************************************************/ /**************************************************/ DWORD WINAPI Multiplication(LPVOID Param) { DWORD t,Index =*(DWORD*) Param; for (DWORD j = 0; j < N; j++) { t=0; for (DWORD l = 0 ; l < N; l++) t+=Array_A[Index][l]*Array_B[l][j]; MultipleArray[Index][j]=t; } return 1; } /**************************************************/ /**************************************************/ void main(int argc, char *argv[]) { DWORD ThreadId[MAX_THREADS]; HANDLE ThreadHandle[MAX_THREADS]; int Index[MAX_THREADS]; if (argc < 3) { fprintf(stderr, "Multiplication requires at least two input\n"); return; } if((argc-1)%2) { fprintf(stderr, "The number of input data must be paired But now is %d\n",argc-1); return; } int Count=(argc-1)/2; N=(int)sqrt(Count*1.0); if ((N*N)!=Count) { fprintf(stderr, "The matrix must be square\n"); return; } // Transfer Data For Easier Programming for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { Array_A[i][j]=atoi(argv[(i*N)+j+1]); Array_B[i][j]=atoi(argv[(i*N)+j+Count+1]); } } // Create N Threads for (int i = 0; i < N; i++) { // Generate unique data for each thread to work with. Index[i]=i; // Create the thread to begin execution on its own. ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]); if (ThreadHandle[i]==NULL) { fprintf(stderr, "Thread could not be created\n"); ExitProcess(3); return; } } // End of main thread creation loop. // Wait until all threads have terminated. WaitForMultipleObjects(N,ThreadHandle,false,INFINITE); // Close all thread handles and free memory allocations. for (int i = 0; i < N; i++) CloseHandle(ThreadHandle[i]); Print(); }
Standard input is empty
prog.cpp:7:1: error: 'DWORD' does not name a type
DWORD N;
^
prog.cpp:8:1: error: 'DWORD' does not name a type
DWORD Array_A[MAX_THREADS][MAX_THREADS];
^
prog.cpp:9:1: error: 'DWORD' does not name a type
DWORD Array_B[MAX_THREADS][MAX_THREADS];
^
prog.cpp:10:1: error: 'DWORD' does not name a type
DWORD MultipleArray[MAX_THREADS][MAX_THREADS];
^
prog.cpp: In function 'void Print()':
prog.cpp:14:22: error: 'N' was not declared in this scope
for (int i = 0; i < N; i++)
^
prog.cpp:18:19: error: 'MultipleArray' was not declared in this scope
printf("%d ",MultipleArray[i][j]);
^
prog.cpp: At global scope:
prog.cpp:23:1: error: 'DWORD' does not name a type
DWORD WINAPI Multiplication(LPVOID Param)
^
prog.cpp:37:33: error: '::main' must return 'int'
void main(int argc, char *argv[])
^
prog.cpp: In function 'int main(int, char**)':
prog.cpp:39:2: error: 'DWORD' was not declared in this scope
DWORD ThreadId[MAX_THREADS];
^
prog.cpp:40:2: error: 'HANDLE' was not declared in this scope
HANDLE ThreadHandle[MAX_THREADS];
^
prog.cpp:45:3: error: return-statement with no value, in function returning 'int' [-fpermissive]
return;
^
prog.cpp:50:3: error: return-statement with no value, in function returning 'int' [-fpermissive]
return;
^
prog.cpp:53:2: error: 'N' was not declared in this scope
N=(int)sqrt(Count*1.0);
^
prog.cpp:57:3: error: return-statement with no value, in function returning 'int' [-fpermissive]
return;
^
prog.cpp:64:4: error: 'Array_A' was not declared in this scope
Array_A[i][j]=atoi(argv[(i*N)+j+1]);
^
prog.cpp:64:38: error: 'atoi' was not declared in this scope
Array_A[i][j]=atoi(argv[(i*N)+j+1]);
^
prog.cpp:65:4: error: 'Array_B' was not declared in this scope
Array_B[i][j]=atoi(argv[(i*N)+j+Count+1]);
^
prog.cpp:74:3: error: 'ThreadHandle' was not declared in this scope
ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]);
^
prog.cpp:74:41: error: 'Multiplication' was not declared in this scope
ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]);
^
prog.cpp:74:69: error: 'ThreadId' was not declared in this scope
ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]);
^
prog.cpp:74:80: error: 'CreateThread' was not declared in this scope
ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]);
^
prog.cpp:78:17: error: 'ExitProcess' was not declared in this scope
ExitProcess(3);
^
prog.cpp:79:4: error: return-statement with no value, in function returning 'int' [-fpermissive]
return;
^
prog.cpp:84:27: error: 'ThreadHandle' was not declared in this scope
WaitForMultipleObjects(N,ThreadHandle,false,INFINITE);
^
prog.cpp:84:46: error: 'INFINITE' was not declared in this scope
WaitForMultipleObjects(N,ThreadHandle,false,INFINITE);
^
prog.cpp:84:54: error: 'WaitForMultipleObjects' was not declared in this scope
WaitForMultipleObjects(N,ThreadHandle,false,INFINITE);
^
prog.cpp:87:30: error: 'CloseHandle' was not declared in this scope
CloseHandle(ThreadHandle[i]);
^
Standard output is empty