Browse Source

Fix Larson's benchmark to support memory space aware allocators.

Ioannis Koutras 13 years ago
parent
commit
55e4828076
1 changed files with 21 additions and 1 deletions
  1. 21 1
      examples/larson.c

+ 21 - 1
examples/larson.c

@@ -4,7 +4,9 @@
 #include <string.h>
 #include <string.h>
 #include <assert.h>
 #include <assert.h>
 #include <unistd.h>
 #include <unistd.h>
+#include <stdlib.h>
 #include <dmmlib/dmmlib.h>
 #include <dmmlib/dmmlib.h>
+#include <dmmlib/initialize_allocator.h>
 #include "lran2.h"
 #include "lran2.h"
 
 
 #define MAX_THREADS     100
 #define MAX_THREADS     100
@@ -15,6 +17,17 @@
 enum BOOLEAN { FALSE, TRUE };
 enum BOOLEAN { FALSE, TRUE };
 #endif /* BOOLEAN */
 #endif /* BOOLEAN */
 
 
+/*
+
+#define custom_malloc(size) malloc(size)
+#define custom_free(ptr) free(ptr)
+
+*/
+
+allocator_t allocator;
+#define custom_malloc(size) custom_ahmalloc(&allocator, &allocator.heaps[0], size)
+#define custom_free(ptr) custom_ahfree(&allocator, &allocator.heaps[0], ptr)
+
 typedef void * LPVOID;
 typedef void * LPVOID;
 typedef unsigned long ULONG;
 typedef unsigned long ULONG;
 typedef long long _int64;
 typedef long long _int64;
@@ -270,6 +283,11 @@ int main(void) {
     int num_rounds;
     int num_rounds;
     int chperthread;
     int chperthread;
 
 
+    void *block_from_malloc;
+
+    block_from_malloc = malloc(64000000);
+    initialize_allocator(&allocator, block_from_malloc, 64000000);
+
     printf("Larson benchmark\n");
     printf("Larson benchmark\n");
 
 
     printf("runtime (sec): ") ;
     printf("runtime (sec): ") ;
@@ -284,7 +302,7 @@ int main(void) {
     printf("threads (min, max):   ") ; 
     printf("threads (min, max):   ") ; 
     //scanf("%d %d", &min_threads, &max_threads) ;
     //scanf("%d %d", &min_threads, &max_threads) ;
     min_threads = 1;
     min_threads = 1;
-    max_threads = 1;
+    max_threads = 2;
 
 
     pthread_setconcurrency(max_threads);
     pthread_setconcurrency(max_threads);
 
 
@@ -304,6 +322,8 @@ int main(void) {
 
 
     runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
     runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ;
 
 
+    free(block_from_malloc);
+
     return 0;
     return 0;
 }
 }