Persistent Structs

Persistent Structs

Data structures in nn-os are made to be suitable for persistent applications i.e. they can be stored away and retrieved and all the interim computational structures and params are parts of the struct definition.

With a slight hit on the memory consumption all the necessary buffers for interprocess communications are also stored in the same struct. For example all the needed (char *) buffers for TCP socket communications are within the struct as well. This will reduce the necessary number of mallocs and memcpy() which are expensive calls.

From nnBackPro.h :

typedef struct {                 /* A NET:                                */

	char		  name[32];
	INT			  type;

	LAYER**       Layer;         /* - layers of this net                  */
	LAYER*        InputLayer;    /* - input layer                         */
	INT			  partitionI;    /* - fixed non-overlap					  */
	LAYER*        OutputLayer;   /* - output layer						  */
	ARRAY		  Target;		 /* this is supplied during training      */
	INT			  partitionO[2]; /* - fixed overlapping					  */

	INT			  listen;
	INT			  Axons[2];		 /* - input output layer sockets		  */
	uint32_t	  IPaddr[3];
	uint32_t	  Ports[3];
	unsigned char *buffer[3];	 /* for efficiency purpose only	          */
	INT			  buffsize[3];   /* third buffer for nnACK communications */

	/* these are the local vars that are placed here to make nnOS persistent */

	nnPACKET	  packet[2];
	BOOL		  partition;
	INT			  mode;
	INT			  opcode;
	PQ			  pq;
	REAL		  pqarray[dimPQ];

	REAL          Alpha;         /* - momentum factor                     */
	REAL          Eta;           /* - learning rate                       */
	REAL          Gain;          /* - gain of sigmoid function            */
	REAL          Error;         /* - total net error                     */

	nnPetriNet	  PetriNet;
} NET;

And again:

typedef struct {

	INT		place_num; /* number of places, n */
	INT		trans_num; /* number of transitions, m */

	ARRAY	IRowAdd; /* m dim: Add along the rows of I */
	ARRAY	IMarkingsRowAds;  /* m dim: Add along the rows of IMarkings */
	ARRAY	IMarks; /* n dim: marking of the input array of places */
	ARRAY	IMarksNew; /* n dim: new marking of places after firing */
	ARRAY   trans_firing;    /* m dim: stores which transitions firing */
	ARRAY   tmp1;    /* m dim: stores the intermediate results */
	INT		*progs;  /* m dim: each prog assiged to a transition firing */
	INT		*progs_return; /* m dim: stores the return values of progs */

	MATRIX	I; /* 2D matrices transitions by places */
	MATRIX  IMarkings; /* current input markings vs. transitions */

} nnPetriNet;
This entry was posted in C/C++, Documentation, Software. Bookmark the permalink.

Leave a Reply