fork download
  1. //#include<Windows.h>
  2. #include<stdio.h>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6. #define MAX_THREADS 20
  7. DWORD N;
  8. DWORD Array_A[MAX_THREADS][MAX_THREADS];
  9. DWORD Array_B[MAX_THREADS][MAX_THREADS];
  10. DWORD MultipleArray[MAX_THREADS][MAX_THREADS];
  11. void Print()
  12. {
  13. printf("Result:");
  14. for (int i = 0; i < N; i++)
  15. {
  16. printf("\n");
  17. for (int j = 0; j < N; j++)
  18. printf("%d ",MultipleArray[i][j]);
  19. }
  20. }
  21. /**************************************************/
  22. /**************************************************/
  23. DWORD WINAPI Multiplication(LPVOID Param)
  24. {
  25. DWORD t,Index =*(DWORD*) Param;
  26. for (DWORD j = 0; j < N; j++)
  27. {
  28. t=0;
  29. for (DWORD l = 0 ; l < N; l++)
  30. t+=Array_A[Index][l]*Array_B[l][j];
  31. MultipleArray[Index][j]=t;
  32. }
  33. return 1;
  34. }
  35. /**************************************************/
  36. /**************************************************/
  37. void main(int argc, char *argv[])
  38. {
  39. DWORD ThreadId[MAX_THREADS];
  40. HANDLE ThreadHandle[MAX_THREADS];
  41. int Index[MAX_THREADS];
  42. if (argc < 3)
  43. {
  44. fprintf(stderr, "Multiplication requires at least two input\n");
  45. return;
  46. }
  47. if((argc-1)%2)
  48. {
  49. fprintf(stderr, "The number of input data must be paired But now is %d\n",argc-1);
  50. return;
  51. }
  52. int Count=(argc-1)/2;
  53. N=(int)sqrt(Count*1.0);
  54. if ((N*N)!=Count)
  55. {
  56. fprintf(stderr, "The matrix must be square\n");
  57. return;
  58. }
  59. // Transfer Data For Easier Programming
  60. for (int i = 0; i < N; i++)
  61. {
  62. for (int j = 0; j < N; j++)
  63. {
  64. Array_A[i][j]=atoi(argv[(i*N)+j+1]);
  65. Array_B[i][j]=atoi(argv[(i*N)+j+Count+1]);
  66. }
  67. }
  68. // Create N Threads
  69. for (int i = 0; i < N; i++)
  70. {
  71. // Generate unique data for each thread to work with.
  72. Index[i]=i;
  73. // Create the thread to begin execution on its own.
  74. ThreadHandle[i] = CreateThread(NULL,0,Multiplication,&Index[i],0,&ThreadId[i]);
  75. if (ThreadHandle[i]==NULL)
  76. {
  77. fprintf(stderr, "Thread could not be created\n");
  78. ExitProcess(3);
  79. return;
  80. }
  81. }
  82. // End of main thread creation loop.
  83. // Wait until all threads have terminated.
  84. WaitForMultipleObjects(N,ThreadHandle,false,INFINITE);
  85. // Close all thread handles and free memory allocations.
  86. for (int i = 0; i < N; i++)
  87. CloseHandle(ThreadHandle[i]);
  88. Print();
  89. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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]);
                              ^
stdout
Standard output is empty