static void initializeRoot (Root *rt) { rt->start = (Node *) malloc (sizeof(Node)); rt->end = (Node *) malloc (sizeof(Node)); if ((rt->start == NULL) || (rt->end == NULL)) { printf ("%s Line %d: Out of memory\n", __FILE__, __LINE__); exit (1); } initializeNode (rt->start, 0); initializeNode (rt->end, 0); rt->start->next = rt->end; rt->end->prev = rt->start; }
/** * Sets the Node ID * */ uint8_t WirelessWrapper::setNodeId(uint8_t id) { uint8_t flag = false; config.setNodeId( id ); flag = config.write(); initializeNode(); return flag; }
//main () int main (int argC, char *argV[]) { //Call syntax check if (argC != 2) { printf ("Usage: %s Input_filename\n", argV[0]); exit(1); } //Main variables node *curNode = NULL, *entryNode = NULL, *prevNode = NULL, *rootNode = NULL; FILE *inFile = NULL, *outFile = NULL; int count = 0; //File creation and checks printf ("Opening files...\n"); createFile (&inFile, argV[1], 'r'); createOutputFile (&outFile, argV[1]); //Load the list printf ("Files found and created. Compiling entries...\n"); while (1) { //Stop conditions if (((ferror (inFile)) || (feof (inFile)))) { break; } //Load the next entry from the file entryNode = malloc (sizeof (node)); initializeNode (entryNode); loadEntryNode (entryNode, inFile); //Add it to the tree curNode = insert (entryNode, curNode); if (++count % 1000000 == 0) { printf ("Entry %d sorted...\n", count); } //Clear entry node for the next loop entryNode = NULL; } //Print the now sorted list printf ("%d entries compiled. Writing to file...\n", count); fclose (inFile); rootNode = curNode; while (write_ascending(curNode, rootNode, prevNode, outFile) != 1); //Close everything and free memory printf ("Written. Closing files...\n"); fclose (outFile); return 0;}
//main () int main (int argC, char *argV[]) { //Call syntax check if (argC != 2) { printf ("Usage: %s Input_filename\n", argV[0]); exit (1); } //Main variables FILE *inFile = NULL, *outFile = NULL; node *entry = NULL, *firstNode = NULL; int count = 0; char in; //File creation and checks printf ("Opening files...\n"); createFile (&inFile, argV[1], 'r'); createOutputFile (&outFile, argV[1]); //Load entries into DLL printf ("Files opened. Loading entries...\n"); while (1) { //Stop conditions if (((ferror (inFile)) || (feof (inFile)))) { break; } entry = malloc (sizeof (node)); initializeNode (entry); loadEntry (entry, inFile); firstNode = insertNode (entry, firstNode); entry = NULL; //A counter so the user has some idea of how long it will take if (++count % 100000 == 0) { printf ("%d entries ordered...\n", count); } } fclose (inFile); //Write ordered list to file printf ("%d entries ordered. Writing to file...\n", count); printNodeList (firstNode, outFile); //Close everything and free memory printf ("Writen. Closing files and freeing memory...\n"); fclose (outFile); return 0; }
void insertNode(struct node **root, int elem){ struct node *temp = initializeNode(elem); if(*root == NULL){ *root = temp; return; } struct node *cur = *root, *prev = NULL; while(cur != NULL){ prev = cur; if(elem < cur->data) cur = cur->lptr; else cur = cur->rptr; } if(elem < prev->data) prev->lptr = temp; else prev->rptr = temp; balanceAvl(root); }
struct Page* createDoublyLinkedList(DBSystem* object) { int numPages=object->getNumberOfPages(); int pageSize=object->getPageSize(); struct Page* currentNode; struct Page* head; struct Page* tempNode; for(int i=0;i<10;i++) { tempNode=initializeNode(pageSize); if(i==0){ head=tempNode; currentNode=head; continue; } currentNode->next=tempNode; tempNode->prev=currentNode; currentNode=tempNode; } return head; }
QRemoteObjectRegistry::QRemoteObjectRegistry(QRemoteObjectNode *node, const QString &name) : QRemoteObjectReplica(ConstructWithNode) { connect(this, &QRemoteObjectRegistry::isReplicaValidChanged, this, &QRemoteObjectRegistry::pushToRegistryIfNeeded); initializeNode(node, name); }
static void readDimacsFileCreateList (void) { int lineLength=32768, i, capacity, numLines = 0, from, to, first=0, j; char *line, *word, ch, ch1, *tmpline; Arc *ac = NULL; if ((line = (char *) malloc ((lineLength+1) * sizeof (char))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } if ((word = (char *) malloc ((lineLength+1) * sizeof (char))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } while (fgets (line, lineLength, stdin)) { ++ numLines; #ifdef VERBOSE printf ("Read line %s\n", line); #endif switch (*line) { case 'p': sscanf (line, "%c %s %d %d %d", &ch, word, &numNodes, &numArcs, &numParams); #ifdef VERBOSE printf ("numNodes: %d, numArcs: %d, numParams: %d\n", numNodes, numArcs, numParams); #endif if ((adjacencyList = (Node *) malloc (numNodes * sizeof (Node))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } if ((strongRoots = (Root *) malloc (numNodes * sizeof (Root))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } if ((labelCount = (int *) malloc (numNodes * sizeof (int))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } if ((arcList = (Arc *) malloc (numArcs * sizeof (Arc))) == NULL) { printf ("%s, %d: Could not allocate memory.\n", __FILE__, __LINE__); exit (1); } for (i=0; i<numNodes; ++i) { initializeRoot (&strongRoots[i]); initializeNode (&adjacencyList[i], (i+1)); labelCount[i] = 0; } for (i=0; i<numArcs; ++i) { initializeArc (&arcList[i]); } break; case 'a': tmpline = line; ++ tmpline; tmpline = getNextWord (tmpline, word); from = (int) atoi (word); tmpline = getNextWord (tmpline, word); to = (int) atoi (word); ac = &arcList[first]; ac->from = &adjacencyList[from-1]; ac->to = &adjacencyList[to-1]; if ((from == source) || (to == sink)) { if ((ac->capacities = (int *) malloc (numParams * sizeof (int))) == NULL) { printf ("%s Line %d: Out of memory\n", __FILE__, __LINE__); exit (1); } for (i=0; i<numParams; ++i) { ac->capacities[i] = 0; } } else { if ((ac->capacities = (int *) malloc (sizeof (int))) == NULL) { printf ("%s Line %d: Out of memory\n", __FILE__, __LINE__); exit (1); } } for (j=0; j<(((from == source) || (to == sink)) ? numParams : 1); ++j) { tmpline = getNextWord (tmpline, word); ac->capacities[j] = (int) atoi (word); } ac->capacity = ac->capacities[0]; ++ first; ++ ac->from->numAdjacent; ++ ac->to->numAdjacent; break; case 'n': sscanf (line, "%c %d %c", &ch, &i, &ch1); if (ch1 == 's') { source = i; } else if (ch1 == 't') { sink = i; } else { printf ("Unrecognized character %c on line %d\n", ch1, numLines); exit (1); } break; } } for (i=0; i<numNodes; ++i) { createOutOfTree (&adjacencyList[i]); } for (i=0; i<numArcs; i++) { to = arcList[i].to->number; from = arcList[i].from->number; capacity = arcList[i].capacity; if (!((source == to) || (sink == from) || (from == to))) { if ((source == from) && (to == sink)) { arcList[i].flow = capacity; } else if (from == source) { addOutOfTreeNode (&adjacencyList[from-1], &arcList[i]); } else if (to == sink) { addOutOfTreeNode (&adjacencyList[to-1], &arcList[i]); } else { addOutOfTreeNode (&adjacencyList[from-1], &arcList[i]); } } } free (line); line = NULL; free (word); word = NULL; }
/** * Initializes the class * */ uint8_t WirelessWrapper::initialize(uint8_t m) { uint8_t flag = false; // Serial.begin(115200); // printf_begin(); // Set the mode mode = m; if( mode == MODE_CLIENT ) { Serial.println(F("\n\n** Client ** \n\n")); Serial.println(F("Reading client configuration....")); if( !config.read() ) { Serial.println(F("General error reading configuration; initializing...\n")); if( config.initialize( CONFIG_VERSION, CONFIG_NODE_ID, CONFIG_NODES ) ) { Serial.println(F("Successfully Initialized.\n")); flag = true; } } else { Serial.println(F("Read Configuration; checking version...\n")); if( config.getVersion() != CONFIG_VERSION ) { Serial.println(F("Configuration Version not matched; initializing...\n")); if( config.initialize( CONFIG_VERSION, CONFIG_NODE_ID, CONFIG_NODES ) ) { Serial.println(F("Successfully Re-initialized.\n")); flag = true; } else { Serial.println(F("Error Re-initializing configuration.\n")); } } else { Serial.println(F("Version matches; configuring radio...")); flag = true; } } config.dump(); if(flag) { // Setup and configure radio radio.begin(); radio.enableAckPayload(); // enable payload ack radio.enableDynamicPayloads(); // Ack payloads are dynamic payloads initializeNode(); // TODO: see if we can move this after writeAckPayload radio.writeAckPayload(1, &message_count, sizeof(message_count)); message_count++; Serial.println(F("Radio Details:")); radio.printDetails(); // Dump the configuration of the rf unit for debugging delay(50); // Attach interrupt handler to interrupt #0 (using pin 2) on BOTH the sender and receiver attachInterrupt(0, check_radio, LOW); } } else if( mode == MODE_SERVER ) { Serial.println(F("\n\n** Server ** \n\n")); Serial.println(F("Reading configuration....")); if( !config.read() ) { Serial.println(F("General error reading configuration; initializing...\n")); if( config.initialize( CONFIG_VERSION, CONFIG_NODE_ID, CONFIG_NODES ) ) { Serial.println(F("Successfully Initialized.\n")); flag = true; } } else { Serial.println(F("Read Configuration; checking version...\n")); if( config.getVersion() != CONFIG_VERSION ) { Serial.println(F("Configuration Version not matched; initializing...\n")); if( config.initialize( CONFIG_VERSION, CONFIG_NODE_ID, CONFIG_NODES ) ) { Serial.println(F("Successfully Re-initialized.\n")); flag = true; } else { Serial.println(F("Error Re-initializing configuration.\n")); } } else { Serial.println(F("Version matches; configuring radio...")); flag = true; } } config.dump(); if( flag ) { // Setup and configure radio radio.begin(); radio.enableAckPayload(); // enable payload ack radio.enableDynamicPayloads(); // Ack payloads are dynamic payloads Serial.println(F("\nRadio Details:")); radio.printDetails(); delay(50); for (int i = 0; i < MAX_COMMAND_SIZE; i++) { commandBuffer[i] = 0xff; } radio.powerUp(); //Power up the radio } } Serial.println(F("Initialization complete.")); return flag; } // end initialize
int processLine(char *line, int lineLength) { int tokenCount; char *cursor; int i; char *tokens[9]; char buffer[80]; time_t refTime; time_t currentTime; tokenCount = 0; for (cursor = line, i = 0; i < 9; i++) { if (*cursor == '\0') { tokens[i] = NULL; } else { findToken(&cursor, &(tokens[i])); tokenCount++; } } if (tokenCount == 0) { return 0; } /* Skip over any trailing whitespace. */ while (isspace((int) *cursor)) { cursor++; } /* Make sure we've parsed everything. */ if (*cursor != '\0') { printText("Too many tokens."); return 0; } /* Have parsed the command. Now execute it. */ switch (*(tokens[0])) /* Command code. */ { case 0: /* Empty line. */ case '#': /* Comment. */ return 0; case '?': case 'h': //printUsage(); return 0; case 'v': snprintf(buffer, sizeof buffer, "%s", IONVERSIONNUMBER); printText(buffer); return 0; case '1': initializeNode(tokenCount, tokens); return 0; case '@': if (tokenCount < 2) { printText("Can't set reference time: \ no time."); } else if (strcmp(tokens[1], "0") == 0)
static void master(void) /********************************************************************/ /* One of the MPI processes will be distinguished as a master node. */ /* That master node will call this function only, so this is the */ /* function that controls all the slave nodes. */ /********************************************************************/ { node_t nodeList[MAX_NODES]; int numNodes, j, numSlaves, numOnCall; long colsPerNode, c0, c1; nfs_sparse_mat_t M; double blstart, blstop; long *deps; /* Load the matrix. */ /* This is not yet done, as it could be a bit tricky. It might not fit into RAM on a single node, which means we should really preprocess it first on a machine with plenty of RAM, save the preprocessed version to disk, and use that one here. Then, instead of loading the whole matrix at once, the master node should just load columns as they are needed to send to the workers. All this function really needs to know is the matrix stats - dimensions and such. So we should here fill those fields in. Then make the initializeNode() function above read the needed columns from disk and send them out. */ M.numCols = M.numRows = 0; /* Change this to the real deal. */ /* Find out how many nodes there are. */ MPI_Comm_size(MPI_COMM_WORLD, &numNodes); nodeList[0].status = ST_MASTER; /****************************************************************/ /* If we have more than a handful of nodes, say more than 8, */ /* we should leave at least one `on call' in case another one */ /* dies. Why? Consider the alternative: if a node dies and we */ /* don't have a backup available, then we either have to */ /* give one node twice the work, or re-distribute and re-assign */ /* the matrix columns. This would: */ /* (1) Hugely complicate the code. */ /* (2) Waste bandwidth. */ /* (3) Waste time. */ /* Of course, we could assume that no node ever fails, but that */ /* is a very bad idea. The is the best compromise between */ /* robustness and efficiency that I can think of. */ /* If you don't like it, you can change this single line of */ /* code, but beware that the resulting code will not be fault */ /* tolerant at all! */ /****************************************************************/ numOnCall = ((numNodes >= 8) ? (MIN(1, 0.05*numNodes)) : 0); for (i=1; i<numNodes; i++) nodeList[i].status=ST_WORKING; for (i=0; i<numOnCall; i--) nodeList[numNodes-1-i].status = ST_ONCALL; /* How many columns does each node get? */ for (i=1; i<numNodes; i++) if (nodeList[i].status == ST_WORKING) numSlaves++; colsPerNode = M->numCols/numSlaves; /* Initialize the slave nodes with their needed columns. */ c0 = 0; c1 = c0 + colsPerNode; for (i=0,j=0; i<numSlaves; i++) { do { j++; } while (nodeList[j].status != ST_WORKING); nodeList[j].c0 = c0; nodeList[j].c1 = c1; initializeNode(&nodeList[j]); c0 = c1; c1 = MIN(c0+colsPerNode, M->numCols); } /* We should now be able to just do: */ srand(seed); seedBlockLanczos(seed); startTime = sTime(); msgLog("", "GGNFS-%s : mpi-matsolve", GGNFS_VERSION); msgLog("", "Running on %d (of %d) nodes.", numSlaves, numNodes); blstart = sTime(); if (!(deps = (long *)malloc(M.numCols*sizeof(long)))) { fprintf(stderr, "Severe memory allocation error!\n"); res = -1; } else { res = blockLanczos32(deps, mpi-multB32, mpi-multB_T32, NULL, M.numCols); blstop = sTime(); printf("Returned %d. Block Lanczos took %1.2lf seconds.\n", res, blstop-blstart); msgLog("", "BLanczosTime: %1.1lf", blstop-blstart); } /* Shutdown all of the nodes except this one. */ for (i=1; i<numNodes; i++) { MPI_Send(0, 0, MPI_INT, i, DIETAG, MPI_COMM_WORLD); } /* Now retrieve the actual dependencies (i.e., if there was a matrix pruning step, then we need to get back to the original matrix). Then store them to file. */ }