/** \ingroup dbprim_link * \brief Flush a linked list. * * This function flushes a linked list--that is, it removes each * element from the list. If a \p flush_func is specified, it will be * called on the entry after it has been removed from the list, and * may safely call <CODE>free()</CODE>. * * \param list A pointer to a #link_head_t. * \param flush_func * A pointer to a callback function used to perform * user-specified actions on an element after removing it * from the list. May be \c NULL. See the documentation * for #link_iter_t for more information. * \param extra A \c void pointer that will be passed to \p * flush_func. * * \retval DB_ERR_BADARGS An argument was invalid. */ unsigned long ll_flush(link_head_t *list, link_iter_t flush_func, void *extra) { link_elem_t *elem; unsigned long retval; initialize_dbpr_error_table(); /* initialize error table */ if (!ll_verify(list)) /* Verify arguments */ return DB_ERR_BADARGS; while ((elem = list->lh_first)) { /* Walk through the list... */ ll_remove(list, elem); /* remove the element */ /* call flush function, erroring out if it fails */ if (flush_func && (retval = (*flush_func)(list, elem, extra))) return retval; } list->lh_count = 0; /* clear the list head */ list->lh_first = 0; list->lh_last = 0; return 0; }
int main(int argC, char *args[]) /****************************************************/ { char colName[64], depName[64], str[1024]; double startTime, stopTime; s32 *deps, origC; u32 seed=DEFAULT_SEED; long testMode=0; struct stat fileInfo; nfs_sparse_mat_t M; llist_t C; int i; FILE *fp, *ifp; strcpy(colName, DEFAULT_COLNAME); strcpy(depName, DEFAULT_DEPNAME); printf(START_MSG, GGNFS_VERSION); seed=time(0); /* This probably shouldn't be needed, but whatever. */ seed = ((seed % 1001)*seed) ^ (171*seed); for (i=1; i<argC; i++) { if (strcmp(args[i], "-v")==0) { verbose++; } else if (strcmp(args[i], "-seed")==0) { if ((++i) < argC) { seed = atol(args[i]); } } else if (strcmp(args[i], "-save")==0) { if ((++i) < argC) { matsave_interval = 60 * atoi(args[i]); } } else if (strcmp(args[i], "-test")==0) { testMode = 1; } else if (strcmp(args[i], "--help")==0) { printf("USAGE: %s %s\n", args[0], USAGE); exit(0); } } srand(seed); if (stat("depinf", &fileInfo)) { printf("Could not stat depinf! Are you trying to run %s to soon?\n", args[0]); return -1; } seedBlockLanczos(seed); startTime = sTime(); msgLog("", "GGNFS-%s : matsolve (seed=%" PRIu32 ")", GGNFS_VERSION, seed); printf("Using PRNG seed=%" PRIu32 ".\n", seed); readSparseMat(&M, "spmat"); ll_read(&C, "sp-index"); printf("Verifying column map..."); fflush(stdout); ll_verify(&C); printf("done.\n"); printf("Matrix loaded: it is %" PRId32 " x %" PRId32 ".\n", M.numRows, M.numCols); if (M.numCols < (M.numRows + 64)) { printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n", M.numCols, M.numRows+64); free(M.cEntry); free(M.cIndex); exit(-1); } if (checkMat(&M, delCols, &numDel)) { printf("checkMat() returned some error! Terminating...\n"); exit(-1); } /* We need to know how many columns there were in the original, unpruned matrix, so we know how much memory to allocate for the dependencies. */ if (!(ifp = fopen("depinf", "rb"))) { fprintf(stderr, "Error opening depinf for read!\n"); exit(-1); } readBinField(str, 1024, ifp); while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) { if (strncmp(str, "NUMCOLS: ", 9)==0) { sscanf(&str[9], "%" SCNx32, &origC); } readBinField(str, 1024, ifp); } fclose(ifp); printf("Original matrix had %" PRId32 " columns.\n", origC); if (!(deps = (s32 *)malloc(origC*sizeof(s32)))) { printf("Could not allocate %" PRIu32 " bytes for the dependencies.\n", (u32)(origC*sizeof(s32)) ); free(M.cEntry); free(M.cIndex); return -1; } if (getDependencies(&M, &C, deps, origC, testMode) == 0) { if (!(ifp = fopen("depinf", "rb"))) { fprintf(stderr, "Error opening depinf for read!\n"); exit(-1); } printf("Writing dependencies to file %s.\n", depName); if (!(fp = fopen(depName, "wb"))) { fprintf(stderr, "Error opening %s for write!\n", depName); fclose(ifp); } else { /* Get the header information from depinf. */ readBinField(str, 1024, ifp); while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) { writeBinField(fp, str); readBinField(str,1024,ifp); } if (strncmp(str, "END_HEADER",10)) { fprintf(stderr, "Error: depinf is corrupt!\n"); fclose(ifp); fclose(fp); exit(-1); } writeBinField(fp, str); fclose(ifp); fwrite(deps, sizeof(s32), origC, fp); fclose(fp); } } stopTime = sTime(); printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime); msgLog("", "Heap stats for matsolve run:"); logHeapStats(); free(M.cEntry); free(M.cIndex); free(deps); return 0; }
static void check_init(hash_table_t *table, unsigned long flags, unsigned long mod, unsigned long over, unsigned long under, hash_func_t func, hash_comp_t comp, void *extra, char *how) { if (table->ht_magic != HASH_TABLE_MAGIC) /* Verify magic was set */ printf("FAIL/%s_magic:Initialization failed to set magic number\n", how); else printf("PASS/%s_magic:Initialization set magic number properly\n", how); if (table->ht_flags != flags) /* verify flags were set */ printf("FAIL/%s_flags:Initialization failed to set flags\n", how); else printf("PASS/%s_flags:Initialization set flags properly\n", how); if (table->ht_modulus != mod) /* verify modulus was set */ printf("FAIL/%s_modulus:Initialization failed to set modulus to %ld " "(%ld instead)\n", how, mod, table->ht_modulus); else printf("PASS/%s_modulus:Initialization set modulus to %ld\n", how, mod); if (table->ht_count != 0) /* verify count was set */ printf("FAIL/%s_count:Initialization failed to clear count\n", how); else printf("PASS/%s_count:Initialization set count to 0\n", how); if (table->ht_rollover != over) /* verify rollover was set */ printf("FAIL/%s_rollover:Initialization failed to set rollover to %ld " "(%ld instead)\n", how, over, table->ht_rollover); else printf("PASS/%s_rollover:Initialization set rollover to %ld\n", how, over); if (table->ht_rollunder != under) /* verify rollunder was set */ printf("FAIL/%s_rollunder:Initialization failed to set rollunder to %ld " "(%ld instead)\n", how, under, table->ht_rollunder); else printf("PASS/%s_rollunder:Initialization set rollunder to %ld\n", how, under); if (table->ht_func != func) /* verify func was set */ printf("FAIL/%s_func:Initialization failed to set func\n", how); else printf("PASS/%s_func:Initialization set func properly\n", how); if (table->ht_comp != comp) /* verify comp was set */ printf("FAIL/%s_comp:Initialization failed to set comp\n", how); else printf("PASS/%s_comp:Initialization set comp properly\n", how); if (table->ht_resize != 0) /* verify resize was set */ printf("FAIL/%s_rsize:Initialization failed to set resize\n", how); else printf("PASS/%s_rsize:Initialization set resize properly\n", how); if (table->ht_extra != extra) /* verify extra was set */ printf("FAIL/%s_extra:Initialization failed to set extra\n", how); else printf("PASS/%s_extra:Initialization set extra properly\n", how); if (mod == 0) { if (table->ht_table != 0) /* verify that table was not allocated */ printf("FAIL/%s_table:Initialization failed to clear table\n", how); else printf("PASS/%s_table:Initialization set table to 0\n", how); } else { int i; if (table->ht_table == 0) /* verify that table was not allocated */ printf("FAIL/%s_table:Initialization failed to set table\n", how); else printf("PASS/%s_table:Initialization set table properly\n", how); for (i = 0; i < mod; i++) /* verify buckets initialized */ if (table->ht_table == 0 || i >= table->ht_modulus || !ll_verify(&table->ht_table[i])) printf("FAIL/%s_bucket%d:Initialization failed to initialize " "bucket %d\n", how, i, i); else printf("PASS/%s_bucket%d:Initialization initialized bucket " "%d properly\n", how, i, i); } }