From b0119acc4719e351f3dda682045dfd6afec5c887 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <gonnet@google.com>
Date: Wed, 25 Nov 2015 22:43:36 +0100
Subject: [PATCH] add location and size information to each resource.

---
 examples/test.c            | 4 ++--
 examples/test_bh.c         | 9 +++++----
 examples/test_bh_sorted.c  | 9 +++++----
 examples/test_fmm_sorted.c | 9 +++++----
 examples/test_qr.c         | 2 +-
 src/res.h                  | 6 ++++++
 6 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/examples/test.c b/examples/test.c
index 9d181aa..3a31be3 100644
--- a/examples/test.c
+++ b/examples/test.c
@@ -118,7 +118,7 @@ void test2 ( int m , int n , int k , int nr_threads ) {
     /* Build a task for each tile of the matrix c. */
     for ( i = 0 ; i < m ; i++ )
         for ( j = 0 ; j < n ; j++ ) {
-            rid = qsched_addres( &s , qsched_owner_none , qsched_res_none );
+            rid = qsched_addres( &s , qsched_owner_none , qsched_res_none , NULL , 0 );
             data[0] = i; data[1] = j;
             for ( kk = 0 ; kk < k ; kk++ ) {
                 data[2] = kk;
@@ -222,7 +222,7 @@ void test1 ( int m , int n , int k , int nr_threads ) {
     for ( i = 0 ; i < m ; i++ )
         for ( j = 0 ; j < n ; j++ ) {
             data[0] = i; data[1] = j;
-            rid = qsched_addres( &s , qsched_owner_none , qsched_res_none );
+            rid = qsched_addres( &s , qsched_owner_none , qsched_res_none , NULL , 0 );
             tid = qsched_addtask( &s , 1 , task_flag_none , data , 2*sizeof(int) , 1 );
             qsched_addlock( &s , tid , rid );
             }
diff --git a/examples/test_bh.c b/examples/test_bh.c
index 906fcfd..15f32b0 100644
--- a/examples/test_bh.c
+++ b/examples/test_bh.c
@@ -232,7 +232,7 @@ void cell_split(struct cell *c, struct qsched *s) {
 
   /* Add a resource for this cell if it doesn't have one yet. */
   if (c->res == qsched_res_none)
-    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none);
+    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none, c->parts, sizeof(struct part) * count);
 
 /* Attach a center-of-mass task to the cell. */
 #ifdef COM_AS_TASK
@@ -254,7 +254,6 @@ void cell_split(struct cell *c, struct qsched *s) {
       cp->loc[1] = c->loc[1];
       cp->loc[2] = c->loc[2];
       cp->h = c->h * 0.5;
-      cp->res = qsched_addres(s, qsched_owner_none, c->res);
       if (k & 4) cp->loc[0] += cp->h;
       if (k & 2) cp->loc[1] += cp->h;
       if (k & 1) cp->loc[2] += cp->h;
@@ -320,8 +319,10 @@ void cell_split(struct cell *c, struct qsched *s) {
 
     /* Store the counts and offsets. */
     for (k = 0; k < 8; k++) {
-      progenitors[k]->count = right[k] - left[k] + 1;
-      progenitors[k]->parts = &c->parts[left[k]];
+      cp = progenitors[k];
+      cp->count = right[k] - left[k] + 1;
+      cp->parts = &c->parts[left[k]];
+      cp->res = qsched_addres(s, qsched_owner_none, c->res, cp->parts, sizeof(struct part) * cp->count);
     }
 
     /* Find the first non-empty progenitor */
diff --git a/examples/test_bh_sorted.c b/examples/test_bh_sorted.c
index de3928d..0080bfa 100644
--- a/examples/test_bh_sorted.c
+++ b/examples/test_bh_sorted.c
@@ -595,7 +595,7 @@ void cell_split(struct cell *c, struct qsched *s) {
 
   /* Add a resource for this cell if it doesn't have one yet. */
   if (c->res == qsched_res_none)
-    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none);
+    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none, parts, sizeof(struct part) * count);
 
 /* Attach a center-of-mass task to the cell. */
 #ifdef COM_AS_TASK
@@ -617,7 +617,6 @@ void cell_split(struct cell *c, struct qsched *s) {
       cp->loc[1] = c->loc[1];
       cp->loc[2] = c->loc[2];
       cp->h = c->h * 0.5;
-      cp->res = qsched_addres(s, qsched_owner_none, c->res);
       if (k & 4) cp->loc[0] += cp->h;
       if (k & 2) cp->loc[1] += cp->h;
       if (k & 1) cp->loc[2] += cp->h;
@@ -683,8 +682,10 @@ void cell_split(struct cell *c, struct qsched *s) {
 
     /* Store the counts and offsets. */
     for (k = 0; k < 8; k++) {
-      progenitors[k]->count = right[k] - left[k] + 1;
-      progenitors[k]->parts = &c->parts[left[k]];
+      cp = progenitors[k];
+      cp->count = right[k] - left[k] + 1;
+      cp->parts = &c->parts[left[k]];
+      cp->res = qsched_addres(s, qsched_owner_none, c->res, cp->parts, sizeof(struct part) * cp->count);
     }
 
     /* Find the first non-empty progenitor */
diff --git a/examples/test_fmm_sorted.c b/examples/test_fmm_sorted.c
index ec33c0d..8578208 100644
--- a/examples/test_fmm_sorted.c
+++ b/examples/test_fmm_sorted.c
@@ -593,7 +593,7 @@ void cell_split(struct cell *c, struct qsched *s) {
 
   /* Add a resource for this cell if it doesn't have one yet. */
   if (c->res == qsched_res_none)
-    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none);
+    c->res = qsched_addres(s, qsched_owner_none, qsched_res_none, parts, sizeof(struct part) * count);
 
 /* Attach a center-of-mass task to the cell. */
 #ifdef COM_AS_TASK
@@ -615,7 +615,6 @@ void cell_split(struct cell *c, struct qsched *s) {
       cp->loc[1] = c->loc[1];
       cp->loc[2] = c->loc[2];
       cp->h = c->h * 0.5;
-      cp->res = qsched_addres(s, qsched_owner_none, c->res);
       if (k & 4) cp->loc[0] += cp->h;
       if (k & 2) cp->loc[1] += cp->h;
       if (k & 1) cp->loc[2] += cp->h;
@@ -681,8 +680,10 @@ void cell_split(struct cell *c, struct qsched *s) {
 
     /* Store the counts and offsets. */
     for (k = 0; k < 8; k++) {
-      progenitors[k]->count = right[k] - left[k] + 1;
-      progenitors[k]->parts = &c->parts[left[k]];
+      cp = progenitors[k];
+      cp->count = right[k] - left[k] + 1;
+      cp->parts = &c->parts[left[k]];
+      cp->res = qsched_addres(s, qsched_owner_none, c->res, cp->parts, sizeof(struct part) * cp->count);
     }
 
     /* Find the first non-empty progenitor */
diff --git a/examples/test_qr.c b/examples/test_qr.c
index b9cdbec..d70977c 100644
--- a/examples/test_qr.c
+++ b/examples/test_qr.c
@@ -531,7 +531,7 @@ void test_qr(int m, int n, int K, int nr_threads, int runs, double* matrix) {
     error("Failed to allocate tid/rid matrix.");
   for (k = 0; k < m * n; k++) {
     tid[k] = qsched_task_none;
-    rid[k] = qsched_addres(&s, qsched_owner_none, qsched_res_none);
+    rid[k] = qsched_addres(&s, qsched_owner_none, qsched_res_none, &rid[k], sizeof(qsched_res_t));
   }
 
   /* Build the tasks. */
diff --git a/src/res.h b/src/res.h
index 52d38c7..2dbd7c3 100644
--- a/src/res.h
+++ b/src/res.h
@@ -32,5 +32,11 @@ struct res {
     
     /* The resource's parent. */
     int parent;
+    
+    /* The resource's data. */
+    void *data;
+    
+    /* The resource's size. */
+    size_t size;
 
     };
-- 
GitLab