From 23d807748be58e5178c04304d9cc788bf122eb12 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@fe.uni-lj.si>
Date: Tue, 11 Feb 2014 15:34:18 +0000
Subject: [PATCH] Make changes in memory allocation. Memory reservation is done, but pointers are not linked into corresponding structure. A lot to be done still. However, check how pointers can be recalculated at any time when the block is copied in memory.

---
 src/Makefile.am            |   10 +-
 src/memory.c               |   87 +++++++++++++++++++++++++++++
 src/memory.h               |    9 +++
 src/initial_distribution.c |    8 ++
 aclocal.m4                 |   10 +-
 src/general.h              |   30 +++++++++
 6 files changed, 141 insertions(+), 13 deletions(-)

diff --git a/aclocal.m4 b/aclocal.m4
index 3094178..da06da5 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.11.6 -*- Autoconf -*-
+# generated automatically by aclocal 1.11.3 -*- Autoconf -*-
 
 # Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
 # 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
@@ -14,8 +14,8 @@
 
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
-m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.69],,
-[m4_warning([this file was generated for autoconf 2.69.
+m4_if(m4_defn([AC_AUTOCONF_VERSION]), [2.68],,
+[m4_warning([this file was generated for autoconf 2.68.
 You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically `autoreconf'.])])
@@ -38,7 +38,7 @@
 [am__api_version='1.11'
 dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
 dnl require some minimum version.  Point them to the right macro.
-m4_if([$1], [1.11.6], [],
+m4_if([$1], [1.11.3], [],
       [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
 ])
 
@@ -54,7 +54,7 @@
 # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
 # This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
 AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.6])dnl
+[AM_AUTOMAKE_VERSION([1.11.3])dnl
 m4_ifndef([AC_AUTOCONF_VERSION],
   [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
 _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
diff --git a/src/Makefile.am b/src/Makefile.am
index 1221acb..09b6e23 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,17 +1,17 @@
 trisurfdir=../
 trisurf_PROGRAMS = trisurf
-trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c bondflip.c main.c
+trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c bondflip.c main.c memory.c
 #trisurf_LDFLAGS = -lm -lconfuse
 shdiscoverdir=../
 shdiscover_PROGRAMS= shdiscover
-shdiscover_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c energy.c sh.c shdiscover.c
+shdiscover_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c energy.c sh.c shdiscover.c memory.c
 AM_CFLAGS = -Wall -Werror
 co_testdir=../
 co_test_PROGRAMS=co_test
-co_test_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c energy.c sh.c co_test.c frame.c bondflip.c
+co_test_SOURCES= general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c energy.c sh.c co_test.c frame.c bondflip.c memory.c
 spherical_trisurfdir=../
 spherical_trisurf_PROGRAMS = spherical_trisurf
-spherical_trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c spherical_trisurf.c sh.c bondflip.c
+spherical_trisurf_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c spherical_trisurf.c sh.c bondflip.c memory.c
 spherical_trisurf_ffdir=../
 spherical_trisurf_ff_PROGRAMS = spherical_trisurf_ff
-spherical_trisurf_ff_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c spherical_trisurf_ff.c sh.c bondflip.c
+spherical_trisurf_ff_SOURCES = general.c vertex.c bond.c triangle.c cell.c vesicle.c initial_distribution.c io.c frame.c energy.c timestep.c vertexmove.c spherical_trisurf_ff.c sh.c bondflip.c memory.c
diff --git a/src/general.h b/src/general.h
index f3328f6..afd238b 100644
--- a/src/general.h
+++ b/src/general.h
@@ -240,14 +240,40 @@
     ts_spharm *sphHarmonics;
 } ts_vesicle;
 
-
-
+typedef struct {
+    ts_uint vertex_no;
+    ts_uint ncmax[3];
+    ts_vesicle *vesicle;
+    ts_vertex_list *vlist;
+    ts_bond_list *blist;
+    ts_triangle_list *tlist;
+    ts_cell_list *clist;
+    ts_vertex **vtx_ptr;
+    ts_vertex *vtx;
+    ts_vertex *vtx_neighbours;
+    ts_vertex **vtx_neighbours_ptr;
+    ts_bond **vtx_neighbond;
+    ts_triangle **tristar;
+    ts_triangle **tria_ptr;
+    ts_triangle *tria;
+    ts_triangle **trianeigh;
+    ts_bond **bond_ptr;
+    ts_bond *bond;
+    ts_cell **cell_ptr;
+    ts_cell *cell;
+    ts_vertex **cell_ocupancy;
+ /*   ts_spharm *sphHarmonics; */
+} ts_memory;
 
 /* GLOBAL VARIABLES */
 
 int quiet;
 
 
+/* ERROR CODES */
+#define TS_ERR_MEM_ALLOC 1
+
+
 /* FUNCTIONS */
 
 /** Non-fatal error function handler:
diff --git a/src/initial_distribution.c b/src/initial_distribution.c
index 382750b..35470a9 100644
--- a/src/initial_distribution.c
+++ b/src/initial_distribution.c
@@ -9,14 +9,20 @@
 #include "triangle.h"
 #include "initial_distribution.h"
 #include "energy.h"
+#include "memory.h"
 
 ts_vesicle *initial_distribution_dipyramid(ts_uint nshell, ts_uint ncmax1, ts_uint ncmax2, ts_uint ncmax3, ts_double stepsize){
     ts_fprintf(stderr,"Starting initial_distribution on vesicle with %u shells!...\n",nshell);
 	ts_bool retval;
     ts_uint no_vertices=5*nshell*nshell+2;
 
+    ts_memory mem;
+    mem.vertex_no=no_vertices;
+    mem.ncmax[0]=ncmax1;
+    mem.ncmax[1]=ncmax2;
+    mem.ncmax[2]=ncmax3;
 
-	
+	init_memory_block(&mem);
     ts_vesicle *vesicle=init_vesicle(no_vertices,ncmax1,ncmax2,ncmax3,stepsize);
 
 //TODO: debugging only. Please remove ASAP!
diff --git a/src/memory.c b/src/memory.c
new file mode 100644
index 0000000..bdd2c13
--- /dev/null
+++ b/src/memory.c
@@ -0,0 +1,87 @@
+#include<stdlib.h>
+#include<unistd.h>
+#include"general.h"
+#include"vesicle.h"
+#include "memory.h"
+
+ts_bool init_memory_block(ts_memory *mem){
+/* calculate number of bonds, triangles */
+ts_uint nbonds=3*(mem->vertex_no-2);
+ts_uint ntria=2*(mem->vertex_no-2);
+ts_uint ncells=mem->ncmax[0]*mem->ncmax[1]*mem->ncmax[2];
+
+ts_uint memsize=sizeof(ts_vesicle)+
+  sizeof(ts_vertex_list)+ sizeof(ts_bond_list)+ sizeof(ts_triangle_list) +
+  sizeof(ts_cell_list) +
+  mem->vertex_no*(sizeof(ts_vertex)+sizeof(ts_vertex *)) +
+  nbonds*(sizeof(ts_bond)+sizeof(ts_bond *))+
+  ntria*(sizeof(ts_triangle)+ sizeof(ts_triangle *))+
+  ncells*(sizeof(ts_cell)+ sizeof(ts_cell *))+
+  MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_vertex *)+
+  MAX_TRISTAR*mem->vertex_no*sizeof(ts_triangle *)+
+  MAX_VTXNEIGH*mem->vertex_no*sizeof(ts_bond *)+
+  3*ntria*sizeof(ts_triangle *)+
+  MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *);
+/* here add size of memory for additional structures!!! */ 
+printf("The page size for this system is %ld bytes.\n",
+	       sysconf(_SC_PAGESIZE)); /* _SC_PAGE_SIZE is OK too. */
+ 
+printf("We need to initialize %d B of memory to hold info about vesicle\n",memsize);
+
+void *ptr=calloc(1,memsize);
+
+    if(ptr==NULL) fatal("Couldn't initialize memory block in memory.c", TS_ERR_MEM_ALLOC);
+
+/*initialize pointers */
+void *rptr=ptr;
+//Vesicle and basic lists
+mem->vesicle=(ts_vesicle *)rptr;
+rptr+=sizeof(ts_vesicle);
+mem->vlist=(ts_vertex_list *)rptr;
+rptr+=sizeof(ts_vertex_list);
+mem->blist=(ts_bond_list *)rptr;
+rptr+=sizeof(ts_bond_list);
+mem->tlist=(ts_triangle_list *)rptr;
+rptr+=sizeof(ts_triangle_list);
+mem->clist=(ts_cell_list *)rptr;
+rptr+=sizeof(ts_cell_list);
+
+//Vertex related memory
+mem->vtx_ptr=(ts_vertex **)rptr;
+rptr+=mem->vertex_no*sizeof(ts_vertex *);
+mem->vtx=(ts_vertex *)rptr;
+rptr+=mem->vertex_no*sizeof(ts_vertex);
+mem->vtx_neighbours_ptr=(ts_vertex **)rptr;
+rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_vertex *);
+mem->tristar=(ts_triangle **)rptr;
+rptr+=mem->vertex_no*MAX_TRISTAR*sizeof(ts_triangle *);
+mem->vtx_neighbond=(ts_bond **)rptr;
+rptr+=mem->vertex_no*MAX_VTXNEIGH*sizeof(ts_bond *);
+
+
+//Bond related memory
+mem->bond_ptr=(ts_bond **)rptr;
+rptr+=nbonds*sizeof(ts_bond *);
+mem->bond=(ts_bond *)rptr;
+rptr+=nbonds*sizeof(ts_bond);
+
+
+//Triangle related memory
+mem->tria_ptr=(ts_triangle **)rptr;
+rptr+=ntria*sizeof(ts_triangle *);
+mem->tria=(ts_triangle *)rptr;
+rptr+=ntria*sizeof(ts_triangle);
+mem->trianeigh=(ts_triangle **)rptr;
+rptr+=ntria*3*sizeof(ts_triangle *);
+
+//Cell related memory
+mem->cell_ptr=(ts_cell **)rptr;
+rptr+=ncells*sizeof(ts_cell *);
+mem->cell=(ts_cell *)rptr;
+rptr+=ncells*sizeof(ts_cell);
+mem->cell_ocupancy=(ts_vertex **)rptr;
+rptr+= MAX_CELL_OCCUPANCY*ncells*sizeof(ts_vertex *);
+printf("Ptr diff in b=%ld\n",(rptr-ptr));
+    
+return TS_SUCCESS;
+}
diff --git a/src/memory.h b/src/memory.h
new file mode 100644
index 0000000..eb49b2f
--- /dev/null
+++ b/src/memory.h
@@ -0,0 +1,9 @@
+#ifndef _h_memory
+#define _h_memory
+#include "general.h"
+
+#define MAX_TRISTAR 8
+#define MAX_VTXNEIGH 7
+#define MAX_CELL_OCCUPANCY 8
+ts_bool init_memory_block(ts_memory *mem);
+#endif

--
Gitblit v1.9.3