void network_stats_wrapper(int *tails, int *heads, int *timings, int *time, int *lasttoggle, int *dnedges, int *dn, int *y0tails, int *y0heads,int *y0dn,int *y0dnedges,double *y0nodalstatus, int *dflag, int *bipartite, int *nterms, char **funnames, char **sonames, double *inputs, double *nodalstatus, double *stats) { int directed_flag; Vertex n_nodes; Edge n_edges, y0n_edges; Network nw[2]; Network y0[1]; Model *m; Vertex bip; double * negstatus; /* Rprintf("prestart with setup\n"); */ n_nodes = (Vertex)*dn; Vertex y0n_nodes = (Vertex)*y0dn; n_edges = (Edge)*dnedges; y0n_edges = (Edge)*y0dnedges; directed_flag = *dflag; bip = (Vertex)*bipartite; negstatus = (double *)malloc( n_nodes * sizeof(double)); /*set to negative */ for (int i=0; i<n_nodes; i++) negstatus[i] = 1.0 ; if(*lasttoggle == 0) lasttoggle = NULL; m=ModelInitialize(*funnames, *sonames, &inputs, *nterms, n_nodes, nodalstatus); nw[0]=NetworkInitialize(NULL, NULL, 0, n_nodes, directed_flag, bip, *timings?1:0, *timings?*time:0, *timings?lasttoggle:NULL, negstatus); y0[0]=NetworkInitialize(y0tails, y0heads, y0n_edges, y0n_nodes, directed_flag, bip, 0, 0, NULL, y0nodalstatus); /* Compute the change statistics and copy them to stats for return to R. Note that stats already has the statistics of an empty network, so d_??? statistics will add on to them, while s_??? statistics will simply overwrite them. */ SummStats(n_edges, n_nodes, tails, heads, nw, m, stats, y0); ModelDestroy(m); NetworkDestroy(nw); }
bool TCPServer::initialize(int port) { #ifdef __WIN32__ if (!NetworkIsInitialized()) NetworkInitialize(); #endif if (isOpen()) { LWARNING("Already initialized, aborting initialize."); return false; } _serverSocket = socket(AF_INET, SOCK_STREAM, 0); if (_serverSocket < 0) return false; // set all values in structs to zero memset(&_serv_addr, 0, sizeof(_serv_addr)); _serv_addr.sin_family = AF_INET; _serv_addr.sin_addr.s_addr = INADDR_ANY; _serv_addr.sin_port = htons(port); if (bind(_serverSocket, (struct sockaddr *) &_serv_addr,sizeof(_serv_addr)) < 0) { LERROR("Could not bind port: " << port); return false; } // start listen listen(_serverSocket,5); LINFO("Successfully initialized socket on port " << port); return true; }
void network_stats_wrapper(int *tails, int *heads, int *timings, int *time, int *lasttoggle, int *dnedges, int *dn, int *dflag, int *bipartite, int *nterms, char **funnames, char **sonames, double *inputs, double *stats) { int directed_flag; Vertex n_nodes; Edge n_edges; Network nw[2]; Model *m; Vertex bip; /* Rprintf("prestart with setup\n"); */ n_nodes = (Vertex)*dn; n_edges = (Edge)*dnedges; directed_flag = *dflag; bip = (Vertex)*bipartite; if(*lasttoggle == 0) lasttoggle = NULL; m=ModelInitialize(*funnames, *sonames, &inputs, *nterms); nw[0]=NetworkInitialize(NULL, NULL, 0, n_nodes, directed_flag, bip, *timings?1:0, *timings?*time:0, *timings?lasttoggle:NULL); /* Compute the change statistics and copy them to stats for return to R. Note that stats already has the statistics of an empty network, so d_??? statistics will add on to them, while s_??? statistics will simply overwrite them. */ SummStats(n_edges, tails, heads, nw, m, stats); ModelDestroy(m); NetworkDestroy(nw); }
void CEngine::Initialize() { if(!NetworkInitialize()) throw CException(); TaskHandler.StartWorkerThread(); ChannelHandler.StartWorkerThread(); ServerChannelHandler.StartWorkerThread(); Tracker.Start(); StartTrackerServer(); StartPeerServer(); }
/** * InitDevice - Local routine to initialise one real device * * @param device: type of device * * Remember that device can be VMIC, SHMEM or NETWORK. * * @return device initialisation on success; Not initialised error otherwise. */ static XmemError InitDevice(XmemDevice device) { switch (device) { case XmemDeviceVMIC: routines.GetAllNodeIds = VmicGetAllNodeIds; routines.RegisterCallback = VmicRegisterCallback; routines.Wait = VmicWait; routines.Poll = VmicPoll; routines.SendTable = VmicSendTable; routines.RecvTable = VmicRecvTable; routines.SendMessage = VmicSendMessage; routines.CheckTables = VmicCheckTables; routines.SendSoftWakeup = VmicSendSoftWakeup; return VmicInitialize(); case XmemDeviceSHMEM: routines.GetAllNodeIds = ShmemGetAllNodeIds; routines.RegisterCallback = ShmemRegisterCallback; routines.Wait = ShmemWait; routines.Poll = ShmemPoll; routines.SendTable = ShmemSendTable; routines.RecvTable = ShmemRecvTable; routines.SendMessage = ShmemSendMessage; routines.CheckTables = ShmemCheckTables; routines.SendSoftWakeup = ShmemSendSoftWakeup; return ShmemInitialize(); case XmemDeviceNETWORK: routines.GetAllNodeIds = NetworkGetAllNodeIds; routines.RegisterCallback = NetworkRegisterCallback; routines.Wait = NetworkWait; routines.Poll = NetworkPoll; routines.SendTable = NetworkSendTable; routines.RecvTable = NetworkRecvTable; routines.SendMessage = NetworkSendMessage; routines.CheckTables = NetworkCheckTables; routines.SendSoftWakeup = NetworkSendSoftWakeup; return NetworkInitialize(); default: break; } return XmemErrorNOT_INITIALIZED; }
/*Takes vectors of doubles for edges; used only when constructing from inputparams. */ Network NetworkInitializeD(double *tails, double *heads, Edge nedges, Vertex nnodes, int directed_flag, Vertex bipartite, int lasttoggle_flag, int time, int *lasttoggle) { /* *** don't forget, tail -> head */ Vertex *itails=(Vertex*)malloc(sizeof(Vertex)*nedges); Vertex *iheads=(Vertex*)malloc(sizeof(Vertex)*nedges); for(Edge i=0; i<nedges; i++){ itails[i]=tails[i]; iheads[i]=heads[i]; } Network nw=NetworkInitialize(itails,iheads,nedges,nnodes,directed_flag,bipartite,lasttoggle_flag, time, lasttoggle); free(itails); free(iheads); return nw; }
void Engine::init() { // Sets up the main logger. setupLogger(); // Creates the task system. taskPool = TaskPoolCreate( AllocatorGetThis(), 2 ); NetworkInitialize(); ResourcesInitialize(); InputInitialize(); GraphicsInitialize(); // Creates the resource manager. resourceManager = AllocateThis(ResourceManager); resourceManager->setTaskPool( taskPool ); // Registers default resource loaders. resourceManager->setupResourceLoaders( ResourceLoaderGetType() ); // Creates the rendering device. renderDevice = AllocateThis(RenderDevice); #ifdef ENABLE_AUDIO_OPENAL // Creates the audio device. audioDevice = AudioCreateDevice(""); if( audioDevice ) audioDevice->createMainContext(); #endif #ifdef ENABLE_SCRIPTING_LUA // Creates the scripting manager. scriptManager = AllocateThis(ScriptManager); #endif }
void MCMCPhase12 (int *tails, int *heads, int *dnedges, int *dn, int *dflag, int *bipartite, int *nterms, char **funnames, char **sonames, char **MHproposaltype, char **MHproposalpackage, double *inputs, double *theta0, int *samplesize, double *gain, double *meanstats, int *phase1, int *nsub, double *sample, int *burnin, int *interval, int *newnetworktails, int *newnetworkheads, int *fVerbose, int *attribs, int *maxout, int *maxin, int *minout, int *minin, int *condAllDegExact, int *attriblength, int *maxedges, int *mtails, int *mheads, int *mdnedges) { int directed_flag; int nphase1, nsubphases; Vertex n_nodes, bip; Edge n_edges, nmax; Network nw[2]; Model *m; MHproposal MH; nphase1 = *phase1; nsubphases = *nsub; n_nodes = (Vertex)*dn; n_edges = (Edge)*dnedges; nmax = (Edge)*maxedges; bip = (Vertex)*bipartite; GetRNGstate(); /* R function enabling uniform RNG */ directed_flag = *dflag; m=ModelInitialize(*funnames, *sonames, &inputs, *nterms); /* Form the missing network */ nw[0]=NetworkInitialize(tails, heads, n_edges, n_nodes, directed_flag, bip, 0, 0, NULL); MH_init(&MH, *MHproposaltype, *MHproposalpackage, inputs, *fVerbose, nw, attribs, maxout, maxin, minout, minin, *condAllDegExact, *attriblength); MCMCSamplePhase12 (&MH, theta0, *gain, meanstats, nphase1, nsubphases, sample, *samplesize, *burnin, *interval, (int)*fVerbose, nw, m); MH_free(&MH); /* record new generated network to pass back to R */ if(nmax>0 && newnetworktails && newnetworkheads) newnetworktails[0]=newnetworkheads[0]=EdgeTree2EdgeList(newnetworktails+1,newnetworkheads+1,nw,nmax-1); ModelDestroy(m); NetworkDestroy(nw); PutRNGstate(); /* Disable RNG before returning */ }
/***************** void MCMC_wrapper Wrapper for a call from R. and don't forget that tail -> head *****************/ void MCMC_wrapper(int *dnumnets, int *nedges, int *tails, int *heads, int *dn, int *dflag, int *bipartite, int *nterms, char **funnames, char **sonames, char **MHproposaltype, char **MHproposalpackage, double *inputs, double *theta0, int *samplesize, double *sample, int *burnin, int *interval, int *newnetworktails, int *newnetworkheads, int *fVerbose, int *attribs, int *maxout, int *maxin, int *minout, int *minin, int *condAllDegExact, int *attriblength, int *maxedges, int *status){ int directed_flag; Vertex n_nodes, nmax, bip; /* Edge n_networks; */ Network nw[1]; Model *m; MHproposal MH; n_nodes = (Vertex)*dn; /* n_networks = (Edge)*dnumnets; */ nmax = (Edge)abs(*maxedges); bip = (Vertex)*bipartite; GetRNGstate(); /* R function enabling uniform RNG */ directed_flag = *dflag; m=ModelInitialize(*funnames, *sonames, &inputs, *nterms); /* Form the network */ nw[0]=NetworkInitialize(tails, heads, nedges[0], n_nodes, directed_flag, bip, 0, 0, NULL); MH_init(&MH, *MHproposaltype, *MHproposalpackage, inputs, *fVerbose, nw, attribs, maxout, maxin, minout, minin, *condAllDegExact, *attriblength); *status = MCMCSample(&MH, theta0, sample, *samplesize, *burnin, *interval, *fVerbose, nmax, nw, m); MH_free(&MH); /* Rprintf("Back! %d %d\n",nw[0].nedges, nmax); */ /* record new generated network to pass back to R */ if(*status == MCMC_OK && *maxedges>0 && newnetworktails && newnetworkheads) newnetworktails[0]=newnetworkheads[0]=EdgeTree2EdgeList(newnetworktails+1,newnetworkheads+1,nw,nmax-1); ModelDestroy(m); NetworkDestroy(nw); PutRNGstate(); /* Disable RNG before returning */ }
void SAN_wrapper ( int *dnumnets, int *nedges, int *tails, int *heads, int *dn, int *y0tails, int *y0heads,int *y0dn,int *y0nedges,double *y0nodalstatus, int *dflag, int *bipartite, int *nterms, char **funnames, char **sonames, char **MHproposaltype, char **MHproposalpackage, double *inputs, double *nodalstatus, double *theta0, double *tau, int *samplesize, double *sample, int *burnin, int *interval, int *newnetworktails, int *newnetworkheads, int *newnodalstatus, double *invcov, int *fVerbose, int *attribs, int *maxout, int *maxin, int *minout, int *minin, int *condAllDegExact, int *attriblength, int *maxedges, int *status){ int directed_flag; Vertex n_nodes, nmax, bip; Network nw[1],y0[1]; Model *m; MHproposal MH; /* please don't forget: tail -> head */ n_nodes = (Vertex)*dn; Vertex y0n_nodes = (Vertex)*y0dn; nmax = (Edge)abs(*maxedges); bip = (Vertex)*bipartite; GetRNGstate(); /* R function enabling uniform RNG */ directed_flag = *dflag; m=ModelInitialize(*funnames, *sonames, &inputs, *nterms, n_nodes, nodalstatus); /* Form the network */ nw[0]=NetworkInitialize(tails, heads, nedges[0], n_nodes, directed_flag, bip, 0, 0, NULL, nodalstatus); y0[0]=NetworkInitialize(y0tails, y0heads, y0nedges[0], y0n_nodes, directed_flag, bip, 0, 0, NULL, y0nodalstatus); MH_init(&MH, *MHproposaltype, *MHproposalpackage, inputs, *fVerbose, nw, attribs, maxout, maxin, minout, minin, *condAllDegExact, *attriblength); *status = SANSample (&MH, theta0, invcov, tau, sample, *samplesize, *burnin, *interval, *fVerbose, nmax, nw, m,y0); MH_free(&MH); /* Rprintf("Back! %d %d\n",nw[0].nedges, nmax); */ /* record new generated network to pass back to R */ if(*status == MCMC_OK && *maxedges>0 && newnetworktails && newnetworkheads) newnetworktails[0]=newnetworkheads[0]=EdgeTree2EdgeList(newnetworktails+1,newnetworkheads+1,nw,nmax-1); if(*status == MCMC_OK && *maxedges>0 && newnodalstatus){ for (int i=0;i<n_nodes;i++) newnodalstatus[i] = nw->nodalstatus[i]; } ModelDestroy(m); NetworkDestroy(nw); NetworkDestroy(y0); PutRNGstate(); /* Disable RNG before returning */ }
void AllStatistics ( int *tails, int *heads, int *dnedges, int *dn, /* Number of nodes */ int *dflag, /* directed flag */ int *bipartite, int *nterms, char **funnames, char **sonames, double *inputs, double *covmat, int *weightsvector, int *maxNumDyadTypes) { Network *nwp; Vertex n_nodes = (Vertex) *dn; unsigned int directed_flag = *dflag; Vertex nodelistlength, rowmax, *nodelist1, *nodelist2; Vertex bip = (Vertex) *bipartite; Model *m; ModelTerm *mtp; /* Step 1: Initialize empty network and initialize model */ GetRNGstate(); /* Necessary for R random number generator */ nwp=NetworkInitialize((Vertex*)tails, (Vertex*)heads, *dnedges, n_nodes, directed_flag, bip, 0, 0, NULL); m=ModelInitialize(*funnames, *sonames, &inputs, *nterms); /* Step 2: Build nodelist1 and nodelist2, which together give all of the dyads in the network. */ if (BIPARTITE > 0) { /* Assuming undirected in the bipartite case */ nodelistlength = BIPARTITE * (N_NODES-BIPARTITE); rowmax = BIPARTITE + 1; } else { nodelistlength = N_NODES * (N_NODES-1) / (DIRECTED? 1 : 2); rowmax = N_NODES; } nodelist1 = (Vertex *) R_alloc(nodelistlength, sizeof(int)); nodelist2 = (Vertex *) R_alloc(nodelistlength, sizeof(int)); int count = 0; for(int i=1; i < rowmax; i++) { for(int j = MAX(i,BIPARTITE)+1; j <= N_NODES; j++) { for(int d=0; d <= DIRECTED; d++) { /*trivial loop if undirected*/ nodelist1[count] = d==1? j : i; nodelist2[count] = d==1? i : j; count++; } } } /* Step 3: Initialize values of mtp->dstats so they point to the correct spots in the newRow vector. These values will never change. */ double *changeStats = (double *) R_alloc(m->n_stats,sizeof(double)); double *cumulativeStats = (double *) R_alloc(m->n_stats,sizeof(double)); for (int i=0; i < m->n_stats; i++) cumulativeStats[i]=0.0; unsigned int totalStats = 0; for (mtp=m->termarray; mtp < m->termarray + m->n_terms; mtp++){ mtp->dstats = changeStats + totalStats; /* Update mtp->dstats pointer to skip atail by mtp->nstats */ totalStats += mtp->nstats; } if (totalStats != m->n_stats) { Rprintf("I thought totalStats=%d and m->nstats=%d should be the same.\n", totalStats, m->n_stats); } /* Step 4: Begin recursion */ RecurseOffOn(nodelist1, nodelist2, nodelistlength, 0, changeStats, cumulativeStats, covmat, (unsigned int*) weightsvector, *maxNumDyadTypes, nwp, m); /* Step 5: Deallocate memory and return */ ModelDestroy(m); NetworkDestroy(nwp); PutRNGstate(); /* Must be called after GetRNGstate before returning to R */ }