__DEVICE__ void exec_final_outputs (solver_props *props, unsigned int modelid) { int i; for(i=0;i<NUM_ITERATORS;i++){ if (props[i].last_iteration[modelid]) { props[i].last_iteration[modelid] = 0; pre_process(&props[i], modelid); #if defined X_IR_SPIL model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, props[i].model_inputs, props[i].model_outputs, &props[i], 1, modelid); #else model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); #endif in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure // the output data structure holds outputs from the previous iteration and updates/postprocess set values // that will be written to output data by the solver flow of the next iteration /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } }
int insert_signals( T& signal, char * signal_name, char * wu_name, sqlint8_t sah_result_id, std::ifstream& result_file, receiver_config& receiver_cfg, int appid, int max_signals_allowed, list<long>& qpixlist) { int signal_count=0, signal_inserted_count=0, retval=0, qpix; sqlint8_t signal_id=0; result_file.clear(); result_file.seekg(0); while (!result_file.eof()) { result_file >> signal; if (!result_file.eof()) { signal_count++; if (max_signals_allowed == 0 || signal_count <= max_signals_allowed) { if (!(signal.rfi_found = check_values(signal, sah_result_id, wu_name))) { // preprocess only if we have good values retval = pre_process(signal, receiver_cfg); qpixlist.push_back(npix2qpix((long long)signal.q_pix)); } signal.result_id = sah_result_id; if (appid == 2) signal.reserved = 1; // temporary for enhanced rollout signal_id = signal.insert(); if (signal_id) { log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG, "[%s] Inserted %s %"INT8_FMT" for sah result %"INT8_FMT"\n", wu_name, signal_name, INT8_PRINT_CAST(signal_id), INT8_PRINT_CAST(sah_result_id) ); signal_inserted_count++; } else { log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "[%s] Could not insert %s for sah result %"INT8_FMT". SQLCODE is %d. q_pix is %"INT8_FMT" ra is %lf decl is %lf .\n", wu_name, signal_name, sah_result_id, sql_last_error_code(), signal.q_pix, signal.ra, signal.decl ); #if 0 log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL, "[%s] Could not insert %s for sah result %ld. SQLCODE is %d. SQLMSG is %s q_pix is %"INT8_FMT".\n", wu_name, signal_name, sah_result_id, sql_last_error_code(), sql_error_message(), signal.q_pix ); #endif return -1; } } } } log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL, "[%s] Inserted %d out of %d %s(s) for sah result %"INT8_FMT" \n", wu_name, signal_inserted_count, signal_count, signal_name, INT8_PRINT_CAST(sah_result_id) ); }
__DEVICE__ void exec_preprocess (CDATAFORMAT min_time, solver_props *props, unsigned int modelid) { int i; for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ props[i].dirty_states[modelid] = 0 == pre_process(&props[i], modelid); } } }
int main() { int a[10] = {1,3,5,7,9,2,4,6,8,10}; pre_process(a,10); int sum = query(a,2,4); printf("sum of a[2] to a[4] is:%d\n",sum); return 0; }
void GraphImpl::process(ProcessContext& context) { if (!_process) return; pre_process(context); run(context); post_process(context); }
int main() { int n; while (scanf("%d", &n) != EOF) { pre_process(); count = 0; permutation_process(1, n); printf("%d\n", count); } return 0; }
int permute(void *data, int nblobs, size_t szblob, Map map){ int i; int *used_command = (int*)calloc(nblobs, sizeof(int)); void *temp = (void*)malloc(szblob); int current_index; int first_to; char* d = (char*)data; if(verify(map,nblobs)==-1){ free(temp); free(used_command); return -1; } pre_process(data, nblobs, szblob, map); /* Following the pre_process step, all indexes are written to a single time. We can sort them in order, and the instruction at every index in map will be the one that writes to that index in the data. */ qsort(map, nblobs, sizeof(MapEntry), mapsort); for(i=0;i<nblobs;i++){ if(used_command[i] == 1) continue; first_to = map[i].indexTo; memcpy(temp, d + (map[i].indexTo * szblob), szblob); memcpy(d + (map[i].indexTo * szblob), d + (map[i].indexFrom * szblob), szblob); used_command[i] = 1; /* Since my map is sorted, this instruction takes me to the map entry that writes to the previous entry in the cycle I'm currently in */ current_index = map[i].indexFrom; while(map[current_index].indexFrom != first_to){ memcpy(d+(map[current_index].indexTo * szblob), d+(map[current_index].indexFrom * szblob), szblob); used_command[current_index] = 1; current_index = map[current_index].indexFrom; } memcpy(d + (map[current_index].indexTo * szblob), temp, szblob); used_command[current_index] = 1; } free(temp); free(used_command); return 0; }
bool init_tool(int argc, const char** argv, Options* opts) { *opts = Options::parse_options(argc, argv); if(!Options::has_required(*opts)) return false; COLOR_ENABLED = !opts->has_opt("no-color"); FORCE_SCALE = opts->has_opt("force-scale"); SMOOTH = opts->has_opt("smooth"); SCALE_ENERGY = opts->has_opt("energy"); PRINT_SCALE = opts->has_opt("print-scale"); REPORT_PROGRESS = opts->has_opt("progress"); VLOG = std::ofstream(opts->get_opt<std::string>("vlog", "vlog.log")); crf.label_alphabet = &alphabet_synth; baseline_crf.label_alphabet = &alphabet_synth; build_data(*opts); pre_process(alphabet_synth, corpus_synth); pre_process(alphabet_test, corpus_test); alphabet_synth.optimize(); remap(alphabet_synth, corpus_synth); alphabet_test.optimize(); remap(alphabet_test, corpus_test); auto testSize = opts->get_opt<unsigned>("test-corpus-size", 10); for(auto i = testSize; i < corpus_test.size(); i++) corpus_eval.add(corpus_test.input(i), corpus_test.label(i)); corpus_test.set_max_size(testSize); INFO("Synth sequences = " << corpus_synth.size()); INFO("Test sequences = " << corpus_test.size()); INFO("Eval sequences = " << corpus_eval.size()); return true; }
static void parse_layer7_protocol(const unsigned char *s, struct ipt_layer7_info *info) { char filename[MAX_FN_LEN]; char * dir = NULL; char ** subdirs; int n = 0, done = 0; if(strlen(l7dir) > 0) dir = l7dir; else dir = "/etc_ro/l7-protocols"; subdirs = readl7dir(dir); while(subdirs[n] != NULL) { int c = snprintf(filename, MAX_FN_LEN, "%s/%s/%s.pat", dir, subdirs[n], s); //fprintf(stderr, "Trying to find pattern in %s ... ", filename); if(c > MAX_FN_LEN) { exit_error(OTHER_PROBLEM, "Filename beginning with %s is too long!\n", filename); } /* read in the pattern from the file */ if(parse_protocol_file(filename, s, info)) { //fprintf(stderr, "found\n"); done = 1; break; } //fprintf(stderr, "not found\n"); n++; } if(!done) exit_error(OTHER_PROBLEM, "Couldn't find a pattern definition file for %s.\n", s); /* process \xHH escapes and tolower everything. (our regex lib has no case insensitivity option.) */ strncpy(info->pattern, pre_process(info->pattern), MAX_PATTERN_LEN); }
/* Iterates through the classification directory, passing each image to the * c_process() function which performs the actual classification */ void NumberClassifier::classify(void) { int n = c_numbers; if (n < 0) { std::cerr << "Error opening directory" << std::endl; } while (n--) { std::string img_name = std::string(c_list[n]->d_name); int img_num = img_name.at(0) - 0x30; cv::Mat img = cv::imread(c_dir + img_name, CV_LOAD_IMAGE_COLOR); if (img.empty()) std::cerr << "Image not loaded" << std::endl; else { pre_process(img); int guess = c_process(img); if (img_num == guess) correct.at(img_num)++; guesses.at(img_num)++; } delete c_list[n]; } delete c_list; }
void window(element_t ap,element_t p,int a,pairing_t pairing) { static const int W = 1; static const int D = 1<<W; element_t dp[D]; for(int i=0;i<D;i++) element_init_G1(dp[i],pairing); pre_process(dp,p,D); element_set0(ap); for(int i = 32/W-1;i>=0;i--) { int tmp = (a>>(i*W)) & ((1<<W)-1); for(int j=0;j<W;j++) element_double(ap,ap); if(tmp) element_add(ap,ap,dp[tmp]); } }
int main(void) { unsigned int m = 0; unsigned int n = 0; unsigned int i,j; unsigned int max_one_count = 0; unsigned int T_count = 0; unsigned int T; scanf("%d", &T); for(T_count = 0; T_count < T; T_count++) { printf("input #%d\n", T_count + 1); scanf("%d %d", &m, &n); for(i = 0; i < m; i++) { for(j = 0; j < n; j++) { scanf("%d", &matrix[i][j]); } } pre_process(m, n); //把每个1元素,替换成它之前连续1的个数 max_one_count = search_max_submatrix(m, n); printf("%d\n", max_one_count); } return 0; }
int main(int argc, char **argv) /* * Initial main driver for GOMA. Derived from a (1/93) release of * the rf_salsa program by * * Original Authors: John Shadid (1421) * Scott Hutchinson (1421) * Harry Moffat (1421) * * Date: 12/3/92 * * * Updates and Changes by: * Randy Schunk (9111) * P. A. Sackinger (9111) * R. R. Rao (9111) * R. A. Cairncross (Univ. of Delaware) * Dates: 2/93 - 6/96 * * Modified for continuation * Ian Gates * Dates: 2/98 - 10/98 * Dates: 7/99 - 8/99 * * Last modified: Wed June 26 14:21:35 MST 1994 [email protected] * Hello. * * Note: Many modifications from an early 2/93 pre-release * version of rf_salsa were made by various persons * in order to test ideas about moving/deforming meshes... */ { /* Local Declarations */ double time_start, total_time; /* timing variables */ #ifndef PARALLEL /* struct tm *tm_ptr; additional serial timing variables */ time_t now; #endif int error; int i; int j; char **ptmp; char *yo; struct Command_line_command **clc=NULL; /* point to command line structure */ int nclc = 0; /* number of command line commands */ /********************** BEGIN EXECUTION ***************************************/ #ifdef FP_EXCEPT feenableexcept ((FE_OVERFLOW | FE_DIVBYZERO | FE_INVALID)); #endif /* assume number of commands is less than or equal to the number of * arguments in the command line minus 1 (1st is program name) */ /* * Get the name of the executable, yo */ yo = argv[0]; #ifdef PARALLEL MPI_Init(&argc, &argv); time_start = MPI_Wtime(); #endif /* PARALLEL */ #ifndef PARALLEL (void)time(&now); time_start = (double)now; #endif /* PARALLEL */ time_goma_started = time_start; Argv = argv; Argc = argc; #ifdef PARALLEL /* * Determine the parallel processing status, if any. We need to know * pretty early if we're "one of many" or the only process. */ error = MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc); error = MPI_Comm_rank(MPI_COMM_WORLD, &ProcID); /* * Setup a default Proc_config so we can use utility routines * from Aztec */ AZ_set_proc_config(Proc_Config, MPI_COMM_WORLD); /* set the output limit flag if need be */ if( Num_Proc > DP_PROC_PRINT_LIMIT ) Unlimited_Output = FALSE; #ifdef HAVE_MPE_H error = MPE_Init_log(); #endif /* HAVE_MPE_H */ Dim = 0; /* for any hypercube legacy code... */ #endif /* PARALLEL */ #ifndef PARALLEL Dim = 0; ProcID = 0; Num_Proc = 1; #endif /* PARALLEL */ /* * HKM - Change the ieee exception handling based on the machine and * the level of debugging/speed desired. This call currently causes * core dumps for floating point exceptions. */ handle_ieee(); log_msg("--------------"); log_msg("GOMA begins..."); /* * Some initial stuff that only the master process does. */ if ( ProcID == 0 ) { if (argc > 1) { log_msg("Preprocessing command line options."); clc = (struct Command_line_command **) smalloc( argc * sizeof(struct Command_line_command *)); for (i=0; i<argc; i++) { clc[i] = (struct Command_line_command *) smalloc(sizeof(struct Command_line_command)); clc[i]->type = 0; /* initialize command line structure */ clc[i]->i_val = 0; clc[i]->r_val = 0.; clc[i]->string = (char *) smalloc(MAX_COMMAND_LINE_LENGTH*sizeof(char)); for ( j=0; j<MAX_COMMAND_LINE_LENGTH; j++) { clc[i]->string[j] = '\0'; } #ifdef DEBUG fprintf(stderr, "clc[%d]->string is at 0x%x\n", i, clc[i]->string); fprintf(stderr, "clc[%d] is at 0x%x\n", i, clc[i]); #endif } } strcpy(Input_File, "input"); strcpy(Echo_Input_File , "echo_input"); if (argc > 1) translate_command_line(argc, argv, clc, &nclc); ECHO("OPEN", Echo_Input_File); echo_command_line( argc, argv, Echo_Input_File ); print_code_version(); ptmp = legal_notice; while ( strcmp(*ptmp, LAST_LEGAL_STRING) != 0 ) { fprintf(stderr, "%s", *ptmp++); } } /* * Allocate the uniform problem description structure and * the problem description structures on all processors */ error = pd_alloc(); EH(error, "pd_alloc problem"); #ifdef DEBUG fprintf(stderr, "P_%d at barrier after pd_alloc\n", ProcID); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif log_msg("Allocating mp, gn, ..."); error = mp_alloc(); EH(error, "mp_alloc problem"); error = gn_alloc(); EH(error, "gn_alloc problem"); error = ve_alloc(); EH(error, "ve_alloc problem"); error = elc_alloc(); EH(error, "elc_alloc problem"); error = elc_rs_alloc(); EH(error, "elc_alloc problem"); error = cr_alloc(); EH(error, "cr_alloc problem"); error = evp_alloc(); EH(error, "evp_alloc problem"); error = tran_alloc(); EH(error, "tran_alloc problem"); error = eigen_alloc(); EH(error, "eigen_alloc problem"); error = cont_alloc(); EH(error, "cont_alloc problem"); error = loca_alloc(); EH(error, "loca_alloc problem"); error = efv_alloc(); EH(error, "efv_alloc problem"); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before read_input_file()\n", ProcID); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif /* * Read ASCII input file, data files, related exodusII FEM databases. */ if ( ProcID == 0 ) { log_msg("Reading input file ..."); read_input_file(clc, nclc); /* Read ascii input file get file names */ /* update inputed data to account for command line arguments that * might override the input deck... */ log_msg("Overriding any input file specs w/ any command line specs..."); if (argc > 1) apply_command_line(clc, nclc); #ifdef DEBUG DPRINTF(stderr, "apply_command_line() is done.\n"); #endif } /* * The user-defined material properties, etc. available to goma users * mean that some dynamically allocated data needs to be communicated. * * To handle this, sizing information from the input file scan is * broadcast in stages so that the other processors can allocate space * accordingly to hold the data. * * Note: instead of handpacking a data structure, use MPI derived datatypes * to gather and scatter. Pray this is done efficiently. Certainly it costs * less from a memory standpoint. */ #ifdef PARALLEL /* * Make sure the input file was successully processed before moving on */ check_parallel_error("Input file error"); /* * This is some sizing information that helps fit a little bit more * onto the ark later on. */ #ifdef DEBUG fprintf(stderr, "P_%d at barrier before noahs_raven()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif noahs_raven(); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before MPI_Bcast of Noahs_Raven\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif MPI_Bcast(MPI_BOTTOM, 1, Noahs_Raven->new_type, 0, MPI_COMM_WORLD); #ifdef DEBUG fprintf(stderr, "P_%d at barrier after Bcast/before raven_landing()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif /* * Get the other processors ready to handle ark data. */ raven_landing(); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before noahs_ark()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif /* * This is the main body of communicated information, including some * whose sizes were determined because of advanced legwork by the raven. */ noahs_ark(); MPI_Bcast(MPI_BOTTOM, 1, Noahs_Ark->new_type, 0, MPI_COMM_WORLD); /* * Chemkin was initialized on processor zero during the input file * process. Now, distribute it to all processors */ #ifdef USE_CHEMKIN if (Chemkin_Needed) { chemkin_initialize_mp(); } #endif /* * Once the ark has landed, there are additional things that will need to * be sent by dove. Example: BC_Types[]->u-BC arrays. * */ ark_landing(); noahs_dove(); MPI_Bcast(MPI_BOTTOM, 1, Noahs_Dove->new_type, 0, MPI_COMM_WORLD); #endif /* End of ifdef PARALLEL */ /* * We sent the packed line to all processors that contained geometry * creation commands. Now we need to step through it and create * geometry as we go (including possibly reading an ACIS .sat file). * */ /* Check to see if BRK File option exists and if so check if file exits */ if (Brk_Flag == 1) { check_for_brkfile(Brk_File); } check_parallel_error("Error encountered in check for brkfile"); /* Now break the exodus files */ if (Num_Proc > 1 && ProcID == 0 && Brk_Flag == 1) { call_brk(); } check_parallel_error("Error in brking exodus files"); MPI_Barrier(MPI_COMM_WORLD); /* * For parallel execution, assume the following variables will be changed * to reflect the multiple file aspect of the problem. * * FEM file = file.exoII --> file_3of15.exoII * * Output EXODUS II file = out.exoII --> out_3of15.exoII * */ /* * Allocate space for structures holding the EXODUS II finite element * database information and for the Distributed Processing information. * * These are mostly skeletons with pointers that get allocated in the * rd_exoII and rd_dpi routines. Remember to free up those arrays first * before freeing the major pointers. */ EXO_ptr = alloc_struct_1(Exo_DB, 1); init_exo_struct(EXO_ptr); DPI_ptr = alloc_struct_1(Dpi, 1); init_dpi_struct(DPI_ptr); log_msg("Reading mesh from EXODUS II file..."); error = read_mesh_exoII(EXO_ptr, DPI_ptr); /* * Missing files on any processor are detected at a lower level * forcing a return to the higher level * rd_exo --> rd_mesh --> main * Shutdown now, if any of the exodus files weren't found */ if (error < 0) { #ifdef PARALLEL MPI_Finalize(); #endif return(-1); } /* * All of the MPI_Type_commit() calls called behind the scenes that build * the dove, ark and raven really allocated memory. Let's free it up now that * the initial information has been communicated. */ #ifdef PARALLEL MPI_Type_free(&(Noahs_Raven->new_type)); MPI_Type_free(&(Noahs_Ark->new_type)); MPI_Type_free(&(Noahs_Dove->new_type)); #endif /* * Setup the rest of the Problem Description structure that depends on * the mesh that was read in from the EXODUS II file... * * Note that memory allocation and some setup has already been performed * in mm_input()... */ error = setup_pd(); EH( error, "Problem setting up Problem_Description."); /* * Let's check to see if we need the large elasto-plastic global tensors * and allocate them if so */ error = evp_tensor_alloc(EXO_ptr); EH( error, "Problems setting up evp tensors"); /* * Now that we know about what kind of problem we're solving and the * mesh information, let's allocate space for elemental assembly structures * */ #ifdef DEBUG DPRINTF(stderr, "About to assembly_alloc()...\n"); #endif log_msg("Assembly allocation..."); error = assembly_alloc(EXO_ptr); EH( error, "Problem from assembly_alloc"); if (Debug_Flag) { DPRINTF(stderr, "%s: setting up EXODUS II output files...\n", yo); } /* * These are not critical - just niceties. Also, they should not overburden * your db with too much of this - they're capped verbiage compliant routines. */ add_qa_stamp(EXO_ptr); add_info_stamp(EXO_ptr); #ifdef DEBUG fprintf(stderr, "added qa and info stamps\n"); #endif /* * If the output EXODUS II database file is different from the input * file, then we'll need to replicate all the basic mesh information. * But, remember that if we're parallel, that the output file names must * be multiplexed first... */ if ( Num_Proc > 1 ) { multiname(ExoFileOut, ProcID, Num_Proc); multiname(Init_GuessFile, ProcID, Num_Proc); if ( strcmp( Soln_OutFile, "" ) != 0 ) { multiname(Soln_OutFile, ProcID, Num_Proc); } if( strcmp( ExoAuxFile, "" ) != 0 ) { multiname(ExoAuxFile, ProcID, Num_Proc); } if( efv->Num_external_field != 0 ) { for( i=0; i<efv->Num_external_field; i++ ) { multiname(efv->file_nm[i], ProcID, Num_Proc); } } } /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Preprocess the exodus mesh * -> Allocate pointers to structures containing element * side bc info, First_Elem_Side_BC_Array, and * element edge info, First_Elem_Edge_BC_Array. * -> Determine Unique_Element_Types[] array */ #ifdef DEBUG fprintf(stderr, "pre_process()...\n"); #endif log_msg("Pre processing of mesh..."); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif pre_process(EXO_ptr); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Load up a few key indeces in the bfd prototype basis function structures * and make sure that each active eqn/vbl has a bf[v] that points to the * right bfd[]...needs pre_process to find out the number of unique * element types in the problem. */ #ifdef DEBUG fprintf(stderr, "bf_init()...\n"); #endif log_msg("Basis function initialization..."); error = bf_init(EXO_ptr); EH( error, "Problem from bf_init"); /* * check for parallel errors before continuing */ check_parallel_error("Error encountered in problem setup"); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Allocate space for each communication exchange description. */ #ifdef PARALLEL #ifdef DEBUG fprintf(stderr, "P_%d: Parallel cx allocation\n", ProcID); #endif if (DPI_ptr->num_neighbors > 0) { cx = alloc_struct_1(Comm_Ex, DPI_ptr->num_neighbors); Request = alloc_struct_1(MPI_Request, Num_Requests * DPI_ptr->num_neighbors); Status = alloc_struct_1(MPI_Status, Num_Requests * DPI_ptr->num_neighbors); } #endif /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * SET UP THE PROBLEM * * Setup node-based structures * Finalise how boundary conditions are to be handled * Determine what unknowns are at each owned node and then tell * neighboring processors about your nodes * Set up communications pattern for fast unknown updates between * processors. */ (void) setup_problem(EXO_ptr, DPI_ptr); /* * check for parallel errors before continuing */ check_parallel_error("Error encountered in problem setup"); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * CREATE BRK_FILE IF ONE DOES NOT EXIST * * If no Brk_File exists but the option was configured in the input or * optional command we create one now and exit from goma. */ if ( Brk_Flag == 2 ) { write_brk_file(Brk_File, EXO_ptr); exit(0); } /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * WRITE OUT INITIAL INFO TO EXODUS FILE */ /* * Only have to initialize the exodus file if we are using different * files for the output versus the input mesh */ if (strcmp(ExoFile, ExoFileOut)) { /* * Temporarily we'll need to renumber the nodes and elements in the * mesh to be 1-based. After writing, return to the 0 based indexing * that is more convenient in C. */ #ifdef DEBUG fprintf(stderr, "1-base; wr_mesh; 0-base\n"); #endif one_base(EXO_ptr); wr_mesh_exo(EXO_ptr, ExoFileOut, 0); zero_base(EXO_ptr); /* * If running on a distributed computer, augment the plain finite * element information of EXODUS with the description of how this * piece fits into the global problem. */ if (Num_Proc > 1) { #ifdef PARALLEL #ifdef DEBUG fprintf(stderr, "P_%d at barrier before wr_dpi()\n", ProcID); fprintf(stderr, "P_%d ExoFileOut = \"%s\"\n", ProcID, ExoFileOut); error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif wr_dpi(DPI_ptr, ExoFileOut, 0); } } /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * SOLVE THE PROBLEM */ if (Debug_Flag) { switch (Continuation) { case ALC_ZEROTH: P0PRINTF("%s: continue_problem (zeroth order) ...\n", yo); break; case ALC_FIRST: P0PRINTF("%s: continue_problem (first order) ...\n", yo); break; case HUN_ZEROTH: P0PRINTF("%s: hunt_problem (zeroth order) ...\n", yo); break; case HUN_FIRST: P0PRINTF("%s: hunt_problem (first order) ...\n", yo); break; case LOCA: P0PRINTF("%s: do_loca ...\n", yo); break; default: P0PRINTF("%s: solve_problem...\n", yo); break; } } #ifdef DEBUG switch (Continuation) { case ALC_ZEROTH: DPRINTF(stderr, "%s: continue_problem (zeroth order) ...\n", yo); break; case ALC_FIRST: DPRINTF(stderr, "%s: continue_problem (first order) ...\n", yo); break; case HUN_ZEROTH: DPRINTF(stderr, "%s: hunt_problem (zeroth order) ...\n", yo); break; case HUN_FIRST: DPRINTF(stderr, "%s: hunt_problem (first order) ...\n", yo); break; case LOCA: DPRINTF(stderr, "%s: do_loca ...\n", yo); break; default: DPRINTF(stderr, "%s: solve_problem...\n", yo); break; } #endif if( TimeIntegration == TRANSIENT) { Continuation = ALC_NONE; if (Debug_Flag) { P0PRINTF("%s: solve_problem...TRANSIENT superceded Continuation...\n", yo); } #ifdef DEBUG DPRINTF(stderr, "%s: solve_problem...TRANSIENT superceded Continuation...\n", yo); #endif solve_problem(EXO_ptr, DPI_ptr, NULL); } switch (Continuation) { case ALC_ZEROTH: case ALC_FIRST: log_msg("Solving continuation problem"); continue_problem(cx, EXO_ptr, DPI_ptr); break; case HUN_ZEROTH: case HUN_FIRST: log_msg("Solving hunt problem"); hunt_problem(cx, EXO_ptr, DPI_ptr); break; case LOCA: log_msg("Solving continuation problem with LOCA"); error = do_loca(cx, EXO_ptr, DPI_ptr); break; default: log_msg("Solving problem"); if (loca_in->Cont_Alg == LOCA_LSA_ONLY) { error = do_loca(cx, EXO_ptr, DPI_ptr); } else if(TimeIntegration != TRANSIENT) { solve_problem(EXO_ptr, DPI_ptr, NULL); } break; } #ifdef PARALLEL MPI_Barrier(MPI_COMM_WORLD); #endif if (ProcID == 0 && Brk_Flag == 1 && Num_Proc > 1) { fix_output(); } /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * PRINT A MESSAGE TO STDOUT SAYING WE ARE DONE */ P0PRINTF("\n-done\n\n"); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * FREE MEMORY ALLOCATED BY THE PROGRAM */ /* * free the element block / element based structures */ free_element_blocks(EXO_ptr); /* * free nodal based structures */ free_nodes(); #ifdef FREE_PROBLEM free_problem ( EXO_ptr, DPI_ptr ); #endif /* * Free command line stuff */ if ( ProcID == 0 ) { if ( argc > 1 ) { for (i=0; i<argc; i++) { #ifdef DEBUG fprintf(stderr, "clc[%d]->string &= 0x%x\n", i, clc[i]->string); fprintf(stderr, "clc[%d] &= 0x%x\n", i, clc[i]); #endif safer_free((void **) &(clc[i]->string)); safer_free((void **) (clc + i)); } safer_free((void **) &clc); } } /* * Free exodus database structures */ free_exo(EXO_ptr); safer_free((void **) &EXO_ptr); if ( Num_Proc > 1 ) { free_dpi(DPI_ptr); } else { free_dpi_uni(DPI_ptr); } safer_free((void **) &DPI_ptr); /* * Remove front scratch file [/tmp/lu.'pid'.0] */ if (Linear_Solver == FRONT) { unlerr = unlink(front_scratch_directory); WH(unlerr, "Unlink problem with front scratch file"); } #ifdef PARALLEL total_time = ( MPI_Wtime() - time_start )/ 60. ; DPRINTF(stderr, "\nProc 0 runtime: %10.2f Minutes.\n\n",total_time); MPI_Finalize(); #endif #ifndef PARALLEL (void)time(&now); total_time = (double)(now) - time_start; fprintf(stderr, "\nProc 0 runtime: %10.2f Minutes.\n\n",total_time/60); #endif fflush(stdout); fflush(stderr); log_msg("GOMA ends normally."); return (0); }
int main( int argc, char *argv[]) { FILE *f_speech; /* Speech data */ FILE *f_serial; /* Serial bit stream */ FILE *f_rate; int rate, flag_rate; extern FLOAT *new_speech; /* Pointer to new speech data */ INT32 count_frame; int prm[PRM_SIZE_E+1]; /* Analysis parameters. */ INT16 serial[SERIAL_SIZE_E]; /* Output bitstream buffer */ INT16 sp16[L_FRAME]; /* Buffer to read 16 bits speech */ int i; int frame; /* frame counter for VAD*/ INT16 temp16; /* For G.729B */ int nb_words; int dtx_enable; for(i = 0; i < argc; i++){ printf("argument %d : %s\n", i, argv[i]); } printf("\n"); printf("*************************************************************************\n"); printf("**** ITU G.729 ANNEC C+: 6.4, 8.0, and 11.8 KBIT/S SPEECH CODER ****\n"); printf("**** INCLUDING OPTIONAL VAD/DTX/CNG (ANNEX B) ****\n"); printf("*************************************************************************\n"); printf("\n"); printf("------------------ Floating point C simulation ----------------\n"); printf("\n"); printf("------------- Version 2.2 (Release 2, November 2006) ----------\n"); printf("\n"); printf(" Bit rates : 6.4, 8.0, or 11.8 kb/s \n"); printf("\n"); /*-----------------------------------------------------------------------* * Open speech file and result file (output serial bit stream) * *-----------------------------------------------------------------------*/ if (( argc != 4 ) && (argc != 5) ){ printf("Usage : codercp speech_file bitstream_file DTX_flag [bitrate or file_bit_rate]\n"); printf("Format for speech_file:\n"); printf(" Speech is read from a binary file of 16 bits PCM data.\n"); printf("\n"); printf("Format for bitstream_file:\n"); printf(" One (2-byte) synchronization word \n"); printf(" One (2-byte) bit-rate word \n"); printf("\n"); printf("bitrate = 0 (6.4 kb/s), 1 (8 kb/s) or 2 (11.8 kb/s) (default : 8 kb/s)\n"); printf("Format for bitrate_file:\n"); printf(" 1 16bit-Word per frame , =0 bit rate 6.4 kb/s, =1 bit rate 8 kb/s, or =2 bit rate 11.8 kb/s \n"); printf("Forward / Backward structure at 11.8 kb/s \n"); printf("DTX flag:\n"); printf(" 0 to disable the DTX\n"); printf(" 1 to enable the DTX\n"); printf("\n"); exit(1); } if ( (f_speech = fopen(argv[1], "rb")) == NULL) { printf("%s - Error opening file %s !!\n", argv[0], argv[1]); exit(0); } printf(" Input speech file : %s\n", argv[1]); if ( (f_serial = fopen(argv[2], "wb")) == NULL) { printf("%s - Error opening file %s !!\n", argv[0], argv[2]); exit(0); } printf(" Output bitstream file : %s\n", argv[2]); dtx_enable = (int)atoi(argv[3]); if (dtx_enable == 1) printf(" DTX enabled\n"); else printf(" DTX disabled\n"); f_rate = NULL; /* to avoid visual warning */ rate = G729; /* to avoid visual warning */ if(argc != 4) { if ( (f_rate = fopen(argv[4], "rb")) == NULL) { rate = atoi(argv[4]); if( rate == G729E) printf(" Selected Bitrate : 11.8 kb/s (G.729 Annex E)\n"); else if( rate == G729) printf(" Selected Bitrate : 8.0 kb/s (G.729 Main Recommendation)\n"); else if( rate == G729D) printf(" Selected Bitrate : 6.4 kb/s (G.729 Annec D)\n"); else { printf(" error bit rate indication\n"); printf(" argv[4] = 0 for bit rate 6.4 kb/s (G.729D)\n"); printf(" argv[4] = 1 for bit rate 8 kb/s (G.729)\n"); printf(" argv[4] = 2 for bit rate 11.8 kb/s (G.729E)\n"); exit(-1); } flag_rate = 0; } else { printf(" Selected Bitrate read in file : %s kb/s\n", argv[4]); flag_rate = 1; } } else { flag_rate = 0; rate = G729; printf(" Selected Bitrate : 8.0 kb/s (G.729 Main Recommendation)\n"); } #ifndef OCTET_TX_MODE printf(" OCTET TRANSMISSION MODE is disabled\n"); #endif /*-------------------------------------------------* * Initialization of the coder. * *-------------------------------------------------*/ init_pre_process(); init_coder_ld8c(dtx_enable); /* Initialize the coder */ /* for G.729B */ if(dtx_enable == 1) init_cod_cng(); for(i=0; i<PRM_SIZE_E; i++) prm[i] = 0; /* To force the input and output to be time-aligned the variable SYNC has to be defined. Note: the test vectors were generated with this option disabled */ #ifdef SYNC /* Read L_NEXT first speech data */ fread(sp16, sizeof(INT16), L_NEXT, f_speech); for (i = 0; i < L_NEXT; i++) new_speech[-L_NEXT+i] = (FLOAT) sp16[i]; pre_process(&new_speech[-L_NEXT], L_NEXT); #endif /*-------------------------------------------------------------------------* * Loop for every analysis/transmission frame. * * -New L_FRAME data are read. (L_FRAME = number of speech data per frame) * * -Conversion of the speech data from 16 bit integer to real * * -Call cod_ld8c to encode the speech. * * -The compressed serial output stream is written to a file. * *-------------------------------------------------------------------------* */ frame=0; count_frame = 0L; while( fread((void *)sp16, sizeof(INT16), L_FRAME, f_speech) == L_FRAME){ if( flag_rate == 1) { if( fread(&temp16, sizeof(INT16), 1, f_rate) != 1) { printf("error reading bit_rate in file %s for frame %ld\n", argv[4], count_frame); exit(-1); } rate = (int)temp16; if( (rate < 0) || (rate > 2) ) { printf("error bit_rate in file %s for frame %ld bit rate non avalaible\n", argv[4], count_frame); exit(-1); } } count_frame++; printf(" Frame: %ld\r", count_frame); if (frame == 32767) frame = 256; else frame++; for (i = 0; i < L_FRAME; i++) new_speech[i] = (FLOAT) sp16[i]; pre_process( new_speech, L_FRAME); coder_ld8c(prm, frame, dtx_enable, rate); prm2bits_ld8c(prm, serial); nb_words = (int)serial[1] + 2; fwrite( (void *)serial, sizeof(INT16), nb_words, f_serial); } printf("%ld frames processed\n", count_frame); if(f_serial) fclose(f_serial); if(f_speech) fclose(f_speech); return(0); } /* end of main() */
// Run a single model to completion on a single processor core int exec_cpu(solver_props *props, const char *outputs_dirname, double *progress, unsigned int modelid){ unsigned int i; CDATAFORMAT min_time; unsigned int before_first_iteration = 1; unsigned int last_iteration[NUM_ITERATORS] = {0}; unsigned int dirty_states[NUM_ITERATORS] = {0}; unsigned int ready_outputs[NUM_ITERATORS] = {0}; // Initialize all iterators to running for(i=0;i<NUM_ITERATORS;i++){ props[i].running[modelid] = 1; } init_states(props, modelid); for(i=0;i<NUM_ITERATORS;i++){ solver_writeback(&props[i], modelid); dirty_states[i] = 0; } // TODO Initialize non-constant state initial values // Run simulation to completion while(model_running(props, modelid)){ // Initialize a temporary output buffer init_output_buffer((output_buffer*)(props->ob), modelid); // Run a set of iterations until the output buffer is full or the simulation is complete while (1) { // Find the nearest next_time and catch up min_time = find_min_time(props, modelid); // Buffer any available outputs for(i=0;i<NUM_ITERATORS;i++){ if (ready_outputs[i]) { #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif ready_outputs[i] = 0; } if (dirty_states[i] && (!before_first_iteration && props[i].next_time[modelid] == min_time)) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Update and postprocess phase: x[t+dt] = f(x[t+dt]) // Update occurs before the first iteration and after every subsequent iteration. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (before_first_iteration || props[i].next_time[modelid] == min_time)){ dirty_states[i] = 0 == update(&props[i], modelid); } if(props[i].running[modelid] && (!before_first_iteration && props[i].next_time[modelid] == min_time)){ dirty_states[i] |= 0 == post_process(&props[i], modelid); } } // Advance the iterator. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (!before_first_iteration && props[i].next_time[modelid] == min_time)){ // Now time == next_time last_iteration[i] = solver_advance(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].next_time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Capture outputs for final iteration for(i=0;i<NUM_ITERATORS;i++){ if (last_iteration[i]) { last_iteration[i] = 0; pre_process(&props[i], modelid); model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure (right?) /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } // Cannot continue if all the simulation is complete if (!model_running(props, modelid)) { break; } // Cannot continue if the output buffer is full if (((output_buffer *)(props->ob))->full[modelid]) { break; } before_first_iteration = 0; // Preprocess phase: x[t] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ dirty_states[i] = 0 == pre_process(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Main solver evaluation phase, including inprocess. // x[t+dt] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ if(0 != solver_eval(&props[i], modelid)) { return ERRCOMP; } // Now next_time == time + dt dirty_states[i] = 1; ready_outputs[i] = 1; // Run any in-process algebraic evaluations in_process(&props[i], modelid); } } } // Log outputs from buffer to external api interface // All iterators share references to a single output buffer and outputs dirname. if(0 != log_outputs(props->ob, outputs_dirname, props->modelid_offset, modelid)){ return ERRMEM; } progress[modelid] = (props->time[modelid] - props->starttime) / (props->stoptime - props->starttime); } return SUCCESS; }
int goma_init_(dbl *time1, int *nnodes, int *nelems, int *nnv_in, int *nev_in, int *i_soln, int *i_post) /* * Initial main driver for GOMA. Derived from a (1/93) release of * the rf_salsa program by * * Original Authors: John Shadid (1421) * Scott Hutchinson (1421) * Harry Moffat (1421) * * Date: 12/3/92 * * * Updates and Changes by: * Randy Schunk (9111) * P. A. Sackinger (9111) * R. R. Rao (9111) * R. A. Cairncross (Univ. of Delaware) * Dates: 2/93 - 6/96 * * Modified for continuation * Ian Gates * Dates: 2/98 - 10/98 * Dates: 7/99 - 8/99 * * Last modified: Wed June 26 14:21:35 MST 1994 [email protected] * Hello. * * Note: Many modifications from an early 2/93 pre-release * version of rf_salsa were made by various persons * in order to test ideas about moving/deforming meshes... */ { /* Local Declarations */ double time_start, total_time; /* timing variables */ #ifndef PARALLEL struct tm *tm_ptr; /* additional serial timing variables */ time_t the_time; #endif int error; int i; int j; static int first_goma_call=TRUE; char **ptmp; static const char *yo="goma_init"; struct Command_line_command **clc=NULL; /* point to command line structure */ int nclc = 0; /* number of command line commands */ /********************** BEGIN EXECUTION ***************************************/ /* assume number of commands is less than or equal to the number of * arguments in the command line minus 1 (1st is program name) */ /* * Get the name of the executable, yo */ #ifdef PARALLEL if( first_goma_call ) { Argc = 1; Argv = (char **) smalloc( Argc*sizeof(char *) ); Argv[0] = (char *) yo; MPI_Init(&Argc, &Argv); /*PRS will have to fix this. Too late TAB already did. */ } time_start = MPI_Wtime(); #else /* PARALLEL */ (void) time(&the_time); tm_ptr = gmtime(&the_time); time_start = (double) ( tm_ptr->tm_sec + 60. * ( 60. * ( tm_ptr->tm_yday * 24. + tm_ptr->tm_hour ) + tm_ptr->tm_min ) ); #endif /* PARALLEL */ *time1 = time_start; /* Argv = argv; */ /* Argc = argc; */ time_goma_started = time_start; #ifdef PARALLEL /* * Determine the parallel processing status, if any. We need to know * pretty early if we're "one of many" or the only process. */ error = MPI_Comm_size(MPI_COMM_WORLD, &Num_Proc); error = MPI_Comm_rank(MPI_COMM_WORLD, &ProcID); /* * Setup a default Proc_config so we can use utility routines * from Aztec */ AZ_set_proc_config(Proc_Config, MPI_COMM_WORLD); /* set the output limit flag if need be */ if( Num_Proc > DP_PROC_PRINT_LIMIT ) Unlimited_Output = FALSE; #ifdef HAVE_MPE_H error = MPE_Init_log(); #endif /* HAVE_MPE_H */ Dim = 0; /* for any hypercube legacy code... */ #endif /* PARALLEL */ #ifndef PARALLEL Dim = 0; ProcID = 0; Num_Proc = 1; #endif /* PARALLEL */ /* * HKM - Change the ieee exception handling based on the machine and * the level of debugging/speed desired. This call currently causes * core dumps for floating point exceptions. */ handle_ieee(); log_msg("--------------"); log_msg("GOMA begins..."); #ifdef USE_CGM cgm_initialize(); #endif /* * Some initial stuff that only the master process does. */ /*PRS: Disable this command line stuff for the jas coupled version */ /*-----------------------------------------------------------------*/ /* if ( ProcID == 0 ) */ /* { */ /* if (argc > 1) */ /* { */ /* log_msg("Preprocessing command line options."); */ /* clc = (struct Command_line_command **) */ /* smalloc( argc * sizeof(struct Command_line_command *)); */ /* for (i=0; i<argc; i++) */ /* { */ /* clc[i] = (struct Command_line_command *) */ /* smalloc(sizeof(struct Command_line_command)); */ /* clc[i]->type = 0; /\* initialize command line structure *\/ */ /* clc[i]->i_val = 0; */ /* clc[i]->r_val = 0.; */ /* clc[i]->string = (char *) */ /* smalloc(MAX_COMMAND_LINE_LENGTH*sizeof(char)); */ /* for ( j=0; j<MAX_COMMAND_LINE_LENGTH; j++) */ /* { */ /* clc[i]->string[j] = '\0'; */ /* } */ /* #ifdef DEBUG */ /* fprintf(stderr, "clc[%d]->string is at 0x%x\n", i, clc[i]->string); */ /* fprintf(stderr, "clc[%d] is at 0x%x\n", i, clc[i]); */ /* #endif */ /* } */ /* } */ /* PRS For the JAS version we will use the default input file name "input" */ strcpy(Input_File, "input"); /* if (argc > 1) translate_command_line(argc, argv, clc, &nclc); */ /* print_code_version(); */ /* ptmp = legal_notice; */ /* while ( strcmp(*ptmp, LAST_LEGAL_STRING) != 0 ) */ /* { */ /* fprintf(stderr, "%s", *ptmp++); */ /* } */ /* } */ /* * Allocate the uniform problem description structure and * the problem description structures on all processors */ error = pd_alloc(); EH(error, "pd_alloc problem"); #ifdef DEBUG fprintf(stderr, "P_%d at barrier after pd_alloc\n", ProcID); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif log_msg("Allocating mp, gn, ..."); error = mp_alloc(); EH(error, "mp_alloc problem"); error = gn_alloc(); EH(error, "gn_alloc problem"); error = ve_alloc(); EH(error, "ve_alloc problem"); error = elc_alloc(); EH(error, "elc_alloc problem"); error = elc_rs_alloc(); EH(error, "elc_alloc problem"); error = cr_alloc(); EH(error, "cr_alloc problem"); error = evp_alloc(); EH(error, "evp_alloc problem"); error = tran_alloc(); EH(error, "tran_alloc problem"); error = libio_alloc(); EH(error, "libio_alloc problem"); error = eigen_alloc(); EH(error, "eigen_alloc problem"); error = cont_alloc(); EH(error, "cont_alloc problem"); error = loca_alloc(); EH(error, "loca_alloc problem"); error = efv_alloc(); EH(error, "efv_alloc problem"); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before read_input_file()\n", ProcID); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif /*PRS AGAIN, NO COMMAND LINE OVERRIDES IN THIS JAS3D VERSION */ /* * Read ASCII input file, data files, related exodusII FEM databases. */ if ( ProcID == 0 ) { log_msg("Reading input file ..."); read_input_file(clc, nclc); } /* * The user-defined material properties, etc. available to goma users * mean that some dynamically allocated data needs to be communicated. * * To handle this, sizing information from the input file scan is * broadcast in stages so that the other processors can allocate space * accordingly to hold the data. * * Note: instead of handpacking a data structure, use MPI derived datatypes * to gather and scatter. Pray this is done efficiently. Certainly it costs * less from a memory standpoint. */ #ifdef PARALLEL /* * Make sure the input file was successully processed before moving on */ check_parallel_error("Input file error"); /* * This is some sizing information that helps fit a little bit more * onto the ark later on. */ #ifdef DEBUG fprintf(stderr, "P_%d at barrier before noahs_raven()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif noahs_raven(); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before MPI_Bcast of Noahs_Raven\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif MPI_Bcast(MPI_BOTTOM, 1, Noahs_Raven->new_type, 0, MPI_COMM_WORLD); #ifdef DEBUG fprintf(stderr, "P_%d at barrier after Bcast/before raven_landing()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif /* * Get the other processors ready to handle ark data. */ raven_landing(); #ifdef DEBUG fprintf(stderr, "P_%d at barrier before noahs_ark()\n", ProcID); error = MPI_Barrier(MPI_COMM_WORLD); #endif /* * This is the main body of communicated information, including some * whose sizes were determined because of advanced legwork by the raven. */ noahs_ark(); MPI_Bcast(MPI_BOTTOM, 1, Noahs_Ark->new_type, 0, MPI_COMM_WORLD); /* * Chemkin was initialized on processor zero during the input file * process. Now, distribute it to all processors */ #ifdef USE_CHEMKIN if (Chemkin_Needed) { chemkin_initialize_mp(); } #endif /* * Once the ark has landed, there are additional things that will need to * be sent by dove. Example: BC_Types[]->u-BC arrays. * */ ark_landing(); noahs_dove(); MPI_Bcast(MPI_BOTTOM, 1, Noahs_Dove->new_type, 0, MPI_COMM_WORLD); #endif /* End of ifdef PARALLEL */ /* * We sent the packed line to all processors that contained geometry * creation commands. Now we need to step through it and create * geometry as we go (including possibly reading an ACIS .sat file). * */ #ifdef USE_CGM create_cgm_geometry(); #endif /* * For parallel execution, assume the following variables will be changed * to reflect the multiple file aspect of the problem. * * FEM file = file.exoII --> file_3of15.exoII * * Output EXODUS II file = out.exoII --> out_3of15.exoII * */ /* * Allocate space for structures holding the EXODUS II finite element * database information and for the Distributed Processing information. * * These are mostly skeletons with pointers that get allocated in the * rd_exoII and rd_dpi routines. Remember to free up those arrays first * before freeing the major pointers. */ EXO_ptr = alloc_struct_1(Exo_DB, 1); init_exo_struct(EXO_ptr); DPI_ptr = alloc_struct_1(Dpi, 1); init_dpi_struct(DPI_ptr); log_msg("Reading mesh from EXODUS II file..."); error = read_mesh_exoII(EXO_ptr, DPI_ptr); /* * Missing files on any processor are detected at a lower level * forcing a return to the higher level * rd_exo --> rd_mesh --> main * Shutdown now, if any of the exodus files weren't found */ if (error < 0) { #ifdef PARALLEL MPI_Finalize(); #endif return(-1); } /* * All of the MPI_Type_commit() calls called behind the scenes that build * the dove, ark and raven really allocated memory. Let's free it up now that * the initial information has been communicated. */ #ifdef PARALLEL MPI_Type_free(&(Noahs_Raven->new_type)); MPI_Type_free(&(Noahs_Ark->new_type)); MPI_Type_free(&(Noahs_Dove->new_type)); #endif /* * Setup the rest of the Problem Description structure that depends on * the mesh that was read in from the EXODUS II file... * * Note that memory allocation and some setup has already been performed * in mm_input()... */ error = setup_pd(); EH( error, "Problem setting up Problem_Description."); /* * Let's check to see if we need the large elasto-plastic global tensors * and allocate them if so */ error = evp_tensor_alloc(EXO_ptr); EH( error, "Problems setting up evp tensors"); /* * Now that we know about what kind of problem we're solving and the * mesh information, let's allocate space for elemental assembly structures * */ #ifdef DEBUG DPRINTF(stderr, "About to assembly_alloc()...\n"); #endif log_msg("Assembly allocation..."); error = assembly_alloc(EXO_ptr); EH( error, "Problem from assembly_alloc"); if (Debug_Flag) { DPRINTF(stderr, "%s: setting up EXODUS II output files...\n", yo); } /* * These are not critical - just niceties. Also, they should not overburden * your db with too much of this - they're capped verbiage compliant routines. */ add_qa_stamp(EXO_ptr); add_info_stamp(EXO_ptr); #ifdef DEBUG fprintf(stderr, "added qa and info stamps\n"); #endif /* * If the output EXODUS II database file is different from the input * file, then we'll need to replicate all the basic mesh information. * But, remember that if we're parallel, that the output file names must * be multiplexed first... */ if ( Num_Proc > 1 ) { multiname(ExoFileOut, ProcID, Num_Proc); multiname(Init_GuessFile, ProcID, Num_Proc); if ( strcmp( Soln_OutFile, "" ) != 0 ) { multiname(Soln_OutFile, ProcID, Num_Proc); } if( strcmp( ExoAuxFile, "" ) != 0 ) { multiname(ExoAuxFile, ProcID, Num_Proc); } if( efv->Num_external_field != 0 ) { for( i=0; i<efv->Num_external_field; i++ ) { multiname(efv->file_nm[i], ProcID, Num_Proc); } } } /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Preprocess the exodus mesh * -> Allocate pointers to structures containing element * side bc info, First_Elem_Side_BC_Array, and * element edge info, First_Elem_Edge_BC_Array. * -> Determine Unique_Element_Types[] array */ #ifdef DEBUG fprintf(stderr, "pre_process()...\n"); #endif log_msg("Pre processing of mesh..."); #ifdef PARALLEL error = MPI_Barrier(MPI_COMM_WORLD); #endif pre_process(EXO_ptr); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Load up a few key indeces in the bfd prototype basis function structures * and make sure that each active eqn/vbl has a bf[v] that points to the * right bfd[]...needs pre_process to find out the number of unique * element types in the problem. */ #ifdef DEBUG fprintf(stderr, "bf_init()...\n"); #endif log_msg("Basis function initialization..."); error = bf_init(EXO_ptr); EH( error, "Problem from bf_init"); /* * check for parallel errors before continuing */ check_parallel_error("Error encountered in problem setup"); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * Allocate space for each communication exchange description. */ #ifdef PARALLEL #ifdef DEBUG fprintf(stderr, "P_%d: Parallel cx allocation\n", ProcID); #endif if (DPI_ptr->num_neighbors > 0) { cx = alloc_struct_1(Comm_Ex, DPI_ptr->num_neighbors); Request = alloc_struct_1(MPI_Request, Num_Requests * DPI_ptr->num_neighbors); Status = alloc_struct_1(MPI_Status, Num_Requests * DPI_ptr->num_neighbors); } #endif /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * SET UP THE PROBLEM * * Setup node-based structures * Finalise how boundary conditions are to be handled * Determine what unknowns are at each owned node and then tell * neighboring processors about your nodes * Set up communications pattern for fast unknown updates between * processors. */ (void) setup_problem(EXO_ptr, DPI_ptr); /* * check for parallel errors before continuing */ check_parallel_error("Error encountered in problem setup"); /***********************************************************************/ /***********************************************************************/ /***********************************************************************/ /* * WRITE OUT INITIAL INFO TO EXODUS FILE */ /* * Only have to initialize the exodus file if we are using different * files for the output versus the input mesh */ if (strcmp(ExoFile, ExoFileOut)) { /* * Temporarily we'll need to renumber the nodes and elements in the * mesh to be 1-based. After writing, return to the 0 based indexing * that is more convenient in C. */ #ifdef DEBUG fprintf(stderr, "1-base; wr_mesh; 0-base\n"); #endif one_base(EXO_ptr); wr_mesh_exo(EXO_ptr, ExoFileOut, 0); zero_base(EXO_ptr); /* * If running on a distributed computer, augment the plain finite * element information of EXODUS with the description of how this * piece fits into the global problem. */ if (Num_Proc > 1) { #ifdef PARALLEL #ifdef DEBUG fprintf(stderr, "P_%d at barrier before wr_dpi()\n", ProcID); fprintf(stderr, "P_%d ExoFileOut = \"%s\"\n", ProcID, ExoFileOut); error = MPI_Barrier(MPI_COMM_WORLD); #endif #endif wr_dpi(DPI_ptr, ExoFileOut, 0); } } if (Num_Import_NV > 0 || Num_Import_EV > 0) printf (" Goma will import %d nodal and %d element variables.\n", Num_Import_NV, Num_Import_EV); if (Num_Export_XS > 0 || Num_Export_XP > 0) printf (" Goma will export %d solution and %d post-processing variables.\n", Num_Export_XS, Num_Export_XP); /* Return counts to calling program */ *nnodes = EXO_ptr->num_nodes; *nelems = EXO_ptr->num_elems; *nnv_in = Num_Import_NV; *nev_in = Num_Import_EV; *i_soln = Num_Export_XS; *i_post = Num_Export_XP; return (0); /* Back to animas*/ }
// Run a single model to completion on a single processor core int exec_cpu(solver_props *props, const char *outputs_dirname, double *progress, unsigned int modelid, int resuming){ unsigned int i; CDATAFORMAT min_time; unsigned int last_iteration[NUM_ITERATORS] = {0}; unsigned int dirty_states[NUM_ITERATORS] = {0}; unsigned int ready_outputs[NUM_ITERATORS] = {0}; int inputs_available = 1; // Initialize all iterators to running for(i=0;i<NUM_ITERATORS;i++){ props[i].running[modelid] = 1; } // Run simulation to completion while(model_running(props, modelid) && inputs_available){ // Initialize a temporary output buffer init_output_buffer((output_buffer*)(props->ob), modelid); // Run a set of iterations until the output buffer is full or the simulation is complete while (1) { // Find the nearest next_time and catch up min_time = find_min_time(props, modelid); // Advance any sampled inputs inputs_available = 1; #if NUM_SAMPLED_INPUTS > 0 for (i=NUM_CONSTANT_INPUTS; i<NUM_CONSTANT_INPUTS + NUM_SAMPLED_INPUTS; i++) { sampled_input_t *input = &sampled_inputs[STRUCT_IDX * NUM_SAMPLED_INPUTS + SAMPLED_INPUT_ID(i)]; if (!advance_sampled_input(input, min_time, props->modelid_offset, modelid)) { // If unable to advance, attempt to buffer more input data. inputs_available &= read_sampled_input(input, min_time, outputs_dirname, i, props->modelid_offset, modelid); } } #endif // Buffer any available outputs for(i=0;i<NUM_ITERATORS;i++){ if (ready_outputs[i]) { #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif ready_outputs[i] = 0; } if (dirty_states[i] && (resuming && props[i].next_time[modelid] == min_time)) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Update and postprocess phase: x[t+dt] = f(x[t+dt]) // Update occurs before the first iteration and after every subsequent iteration. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (!resuming || props[i].next_time[modelid] == min_time)){ dirty_states[i] = 0 == update(&props[i], modelid); } if(props[i].running[modelid] && (resuming && props[i].next_time[modelid] == min_time)){ dirty_states[i] |= 0 == post_process(&props[i], modelid); } } // Advance the iterator. for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && (resuming && props[i].next_time[modelid] == min_time)){ // Now time == next_time last_iteration[i] = solver_advance(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].next_time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Capture outputs for final iteration for(i=0;i<NUM_ITERATORS;i++){ if (last_iteration[i]) { last_iteration[i] = 0; pre_process(&props[i], modelid); model_flows(props[i].time[modelid], props[i].model_states, props[i].next_states, &props[i], 1, modelid); in_process(&props[i], modelid); // Updates and postprocess should not write to the output data structure // the output data structure holds outputs from the previous iteration and updates/postprocess set values // that will be written to output data by the solver flow of the next iteration /* update(&props[i], modelid); */ /* post_process(&props[i], modelid); */ #if NUM_OUTPUTS > 0 buffer_outputs(&props[i], modelid); #endif } } // Cannot continue if a sampled input with halt condition has no more data if(!inputs_available) { break; } // Cannot continue if all the simulation is complete if (!model_running(props, modelid)) { break; } // Cannot continue if the output buffer is full if (((output_buffer *)(props->ob))->full[modelid]) { break; } resuming = 1; // Preprocess phase: x[t] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ dirty_states[i] = 0 == pre_process(&props[i], modelid); } } for(i=0;i<NUM_ITERATORS;i++){ if (dirty_states[i] && props[i].time[modelid] == min_time) { solver_writeback(&props[i], modelid); dirty_states[i] = 0; } } // Main solver evaluation phase, including inprocess. // x[t+dt] = f(x[t]) for(i=0;i<NUM_ITERATORS;i++){ if(props[i].running[modelid] && props[i].time[modelid] == min_time){ if(0 != solver_eval(&props[i], modelid)) { return ERRCOMP; } // Now next_time == time + dt dirty_states[i] = 1; ready_outputs[i] = 1; // Run any in-process algebraic evaluations in_process(&props[i], modelid); } } } // Log outputs from buffer to external api interface // All iterators share references to a single output buffer and outputs dirname. if(0 != log_outputs(props->ob, outputs_dirname, props->modelid_offset, modelid)){ return ERRMEM; } progress[modelid] = (props->time[modelid] - props->starttime) / (props->stoptime - props->starttime); } return SUCCESS; }