Browse Source

modified matrix sizes and threads count; inverted tests order

master
Robin Thoni 7 years ago
parent
commit
f22775d816
2 changed files with 18 additions and 12 deletions
  1. 1
    1
      Makefile
  2. 17
    11
      main.c

+ 1
- 1
Makefile View File

1
 CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99
1
 CFLAGS = -Wall -Wextra -Werror -pedantic -std=c99
2
-LDLIBS = -lpthread
2
+LDLIBS = -lpthread -lrt
3
 CC = gcc
3
 CC = gcc
4
 SOURCES = main.c
4
 SOURCES = main.c
5
 OBJS = $(SOURCES:.c=.o)
5
 OBJS = $(SOURCES:.c=.o)

+ 17
- 11
main.c View File

4
 #include <time.h>
4
 #include <time.h>
5
 #include <unistd.h>
5
 #include <unistd.h>
6
 #include <string.h>
6
 #include <string.h>
7
+#include <math.h>
7
 #include <pthread.h>
8
 #include <pthread.h>
8
 
9
 
9
 struct matrix
10
 struct matrix
177
     mat = matrix_generate(mat1.m, mat2.n, 0);
178
     mat = matrix_generate(mat1.m, mat2.n, 0);
178
     unsigned scalars_count = mat1.m * mat2.n;
179
     unsigned scalars_count = mat1.m * mat2.n;
179
     unsigned distribution[thread_count];
180
     unsigned distribution[thread_count];
180
-    unsigned scalar_start = 0;
181
-    //unsigned scalar_start = distribution[0];
182
     matrix_get_thread_scalars_distribution(scalars_count, thread_count, distribution);
181
     matrix_get_thread_scalars_distribution(scalars_count, thread_count, distribution);
182
+    //unsigned scalar_start = 0;
183
+    unsigned scalar_start = distribution[0];
183
     pthread_t threads[thread_count];
184
     pthread_t threads[thread_count];
184
-    //threads[0] = 0;
185
+    threads[0] = 0;
185
 
186
 
186
-    for (unsigned thread_number = 0; thread_number < thread_count; ++thread_number) {
187
+    for (unsigned thread_number = 1; thread_number < thread_count; ++thread_number) {
187
       unsigned scalars_count = distribution[thread_number];
188
       unsigned scalars_count = distribution[thread_number];
188
       if (scalars_count > 0) {
189
       if (scalars_count > 0) {
189
         threads[thread_number] = matrix_mult_parallel_launch_thread(mat1, mat2, mat, scalar_start, scalars_count, thread_number, 1);
190
         threads[thread_number] = matrix_mult_parallel_launch_thread(mat1, mat2, mat, scalar_start, scalars_count, thread_number, 1);
194
       }
195
       }
195
     }
196
     }
196
 
197
 
197
-    //matrix_mult_parallel_launch_thread(mat1, mat2, mat, 0, distribution[0], 0, 0);
198
+    matrix_mult_parallel_launch_thread(mat1, mat2, mat, 0, distribution[0], 0, 0);
198
 
199
 
199
     for (unsigned thread_number = 0; thread_number < thread_count; ++thread_number) {
200
     for (unsigned thread_number = 0; thread_number < thread_count; ++thread_number) {
200
       pthread_t thread = threads[thread_number];
201
       pthread_t thread = threads[thread_number];
237
   long us = (ts->tv_nsec / 1000) % 1000;
238
   long us = (ts->tv_nsec / 1000) % 1000;
238
   long ms = (ts->tv_nsec / 1000000) % 1000;
239
   long ms = (ts->tv_nsec / 1000000) % 1000;
239
   long s =  (ts->tv_nsec / 1000000000) % 1000 + ts->tv_sec;
240
   long s =  (ts->tv_nsec / 1000000000) % 1000 + ts->tv_sec;
240
-  printf("%3lds %3ldms %3ldus %3ldns", s, ms, us, ns);
241
+  long t = (s * 1000000000) + (ms * 1000000) + (us * 1000) + ns;
242
+  printf("%3lds %3ldms %3ldus %3ldns %12ld", s, ms, us, ns, t);
241
 }
243
 }
242
 
244
 
243
 void test(unsigned size, unsigned thread_count)
245
 void test(unsigned size, unsigned thread_count)
256
   printf("%3dcpu %3dthreads %4d*%-4d ", get_cpu_count(), thread_count, size, size);
258
   printf("%3dcpu %3dthreads %4d*%-4d ", get_cpu_count(), thread_count, size, size);
257
   print_time(&time);
259
   print_time(&time);
258
   printf("\n");
260
   printf("\n");
261
+  fflush(stdout);
259
   matrix_free(mat);
262
   matrix_free(mat);
260
 
263
 
261
 }
264
 }
292
 
295
 
293
   check();
296
   check();
294
 
297
 
295
-  unsigned sizes[] = {10, 100};
296
-  unsigned threads_count[] = {1, 4, 16, 64};
298
+  unsigned sizes[] = {10, 100, 1000, 2000, 5000};
299
+  unsigned threads_count = get_cpu_count();
300
+  if (threads_count < 64) {
301
+    threads_count = 64;
302
+  }
297
 
303
 
298
   for (unsigned s = 0; s < sizeof(sizes) / sizeof(*sizes); ++s) {
304
   for (unsigned s = 0; s < sizeof(sizes) / sizeof(*sizes); ++s) {
299
     unsigned size = sizes[s];
305
     unsigned size = sizes[s];
300
-    test(size, 0);
301
-    for (unsigned t = 0; t < sizeof(threads_count) / sizeof(*threads_count); ++t) {
302
-      test(size, threads_count[t]);
306
+    for (unsigned t = threads_count; t > 1; t /= 2) {
307
+      test(size, t);
303
     }
308
     }
309
+    test(size, 0);
304
   }
310
   }
305
 
311
 
306
   return 0;
312
   return 0;

Loading…
Cancel
Save