THREADABLE_FUNCTION_END //start the master thread, locking all the other threads void thread_master_start(int narg,char **arg,void(*main_function)(int narg,char **arg)) { //initialize reducing buffers glb_single_reduction_buf=(float*)malloc(nthreads*sizeof(float)); glb_double_reduction_buf=(double*)malloc(nthreads*sizeof(double)); glb_quadruple_reduction_buf=(float_128*)malloc(nthreads*sizeof(float_128)); //lock the pool thread_pool_locked=true; cache_flush(); //control the proper working of all the threads... thread_sanity_check(); //launch the main function main_function(narg,arg); //free global reduction buffers free(glb_single_reduction_buf); free(glb_double_reduction_buf); free(glb_quadruple_reduction_buf); //exit the thread pool thread_pool_stop(); }
// Main-Program int main(int argc, char* argv[]) { try { main_function(argc, argv); } catch(std::exception & e) { std::cout << "Exception cought: " << e.what() << std::endl; } return EXIT_SUCCESS; }
//start the simul void simul_t::start(int narg,char **arg,void(*main_function)(int narg,char **arg)) { //set verbosity_lv verbosity_lv=2; //init base things init_MPI_thread(narg,arg); //this must be done before everything otherwise rank non properly working //get the number of rank and the id of the local one get_MPI_nranks(); get_MPI_rank(); //associate sigsegv with proper handle signal(SIGSEGV,signal_handler); signal(SIGFPE,signal_handler); signal(SIGXCPU,signal_handler); //print SVN version and configuration and compilation time MASTER_PRINTF("Initializing mecstat, version: %s\n",SVN_VERSION); MASTER_PRINTF("Configured at %s with flags: %s\n",CONFIG_TIME,CONFIG_FLAGS); MASTER_PRINTF("Compiled at %s of %s\n",__TIME__,__DATE__); //initialize the first vector vectors=new vectors_t(); //set no communication buffer comm_buff=NULL; comm_buff_size=0; //check endianness is_little_endian=get_little_endianness(); if(is_little_endian) MASTER_PRINTF("System endianness: little (ordinary machine)\n"); else MASTER_PRINTF("System endianness: big (BG, etc)\n"); //get number of threads #pragma omp parallel { nthreads=omp_get_num_threads(); } MASTER_PRINTF("Using %u threads\n",nthreads); //init the thread array thread_res_arr=NEW_ARRAY_NON_BLOCKING("thread_res_arr",char*,nthreads); //some init missing //now start the threads #pragma omp parallel { //start internal main main_function(narg,arg); } }
static void run (const gchar *name, gint nparams, const GimpParam *param, gint *nreturn_vals, GimpParam **return_vals) { GimpDrawable *drawable; static GimpParam values[1]; GimpPDBStatusType status = GIMP_PDB_EXECUTION_ERROR; GimpRunMode run_mode; run_mode = param[0].data.d_int32; drawable = gimp_drawable_get (param[2].data.d_drawable); INIT_I18N (); *nreturn_vals = 1; *return_vals = values; values[0].type = GIMP_PDB_STATUS; values[0].data.d_status = status; switch (run_mode) { case GIMP_RUN_INTERACTIVE: gimp_get_data (PLUG_IN_PROC, &pvals); /* Since a channel might be selected, we must check wheter RGB or not. */ if (!gimp_drawable_is_rgb (drawable->drawable_id)) { g_message (_("Can only operate on RGB drawables.")); return; } if (! max_rgb_dialog (drawable)) return; break; case GIMP_RUN_NONINTERACTIVE: /* You must copy the values of parameters to pvals or dialog variables. */ pvals.max_p = param[3].data.d_int32; break; case GIMP_RUN_WITH_LAST_VALS: gimp_get_data (PLUG_IN_PROC, &pvals); break; } status = main_function (drawable, NULL); if (run_mode != GIMP_RUN_NONINTERACTIVE) gimp_displays_flush (); if (run_mode == GIMP_RUN_INTERACTIVE && status == GIMP_PDB_SUCCESS) gimp_set_data (PLUG_IN_PROC, &pvals, sizeof (ValueType)); values[0].data.d_status = status; }
int main(int argc, char **argv) { try { main_function(argc, argv); } catch(std::exception& e) { std::cout << "Exception: " << e.what() << " in t-eoExtendedVelocity" << std::endl; } return EXIT_SUCCESS; }
static void *emulation_thread_entry(void *data) { fs_emu_log("emulation thread started\n"); g_fs_emu_emulation_thread_running = 1; #ifdef WINDOWS if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL)) { fs_emu_log("thread priority set to THREAD_PRIORITY_ABOVE_NORMAL\n"); } else { int dwError = GetLastError(); fs_emu_log("Failed to set thread priority (%d)\n", dwError); } #endif #ifdef WITH_NETPLAY if (fs_emu_netplay_enabled()) { fs_emu_log("netplay is enabled - waiting for connection\n"); while (!fs_emu_netplay_connected()) { // waiting for connection fs_emu_msleep(10); if (!fs_emu_netplay_enabled()) { // net play mode was aborted fs_emu_log("netplay aborted\n"); break; } } } #endif void (*main_function)() = data; if (main_function) { fs_emu_log("main function at %p\n", data); main_function(); } else { fs_emu_fatal("main function is NULL pointer\n"); } // call fs_ml_quit in case the quit was not explicitly requested already fs_ml_quit(); g_fs_emu_emulation_thread_running = 0; // with this set, and fs_ml_quit being called, the frame render // function will call fs_ml_stop when the fadeout effect is done g_fs_emu_emulation_thread_stopped = 1; //fs_emu_log("calling fs_ml_stop because emulation thread has ended\n"); //fs_ml_stop(); return NULL; }
int main() { #ifdef _MSC_VER // rng.reseed(42); int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); flag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(flag); // _CrtSetBreakAlloc(100); #endif try { main_function(); } catch(std::exception& e) { std::cout << "Exception: " << e.what() << '\n'; } }
int main(int argc, char* argv[]) { MonoDomain *domain; const char *file; int retval; puts("Ola"); if (argc < 2){ fprintf (stderr, "Please provide an assembly to load\n"); return 1; } file = argv [1]; /* * Load the default Mono configuration file, this is needed * if you are planning on using the dllmaps defined on the * system configuration */ mono_config_parse (NULL); /* * mono_jit_init() creates a domain: each assembly is * loaded and run in a MonoDomain. */ domain = mono_jit_init (file); /* * We add our special internal call, so that C# code * can call us back. */ mono_add_internal_call ("MonoEmbed::gimme", gimme); main_function (domain, file, argc - 1, argv + 1); retval = mono_environment_exitcode_get (); mono_jit_cleanup (domain); getch(); return retval; }
static void *emulation_thread(void *data) { fse_log("[FSE] Emulation thread started\n"); #ifdef WINDOWS set_windows_thread_priority(); #endif #ifdef WITH_NETPLAY if (fs_emu_netplay_enabled()) { fse_log("[NETPLAY] Enabled - waiting for connection...\n"); while (!fs_emu_netplay_connected()) { /* Waiting for connection... */ fs_emu_msleep(10); if (!fs_emu_netplay_enabled()) { /* Net play mode was aborted. */ fse_log("netplay aborted\n"); break; } } } #endif g_fs_emu_emulation_thread_running = 1; void (*main_function)() = data; if (main_function) { fse_log("[FSE] Run main function at %p\n", data); main_function(); } else { fs_emu_fatal("[FSE] NULL pointer main function\n"); } /* Call fs_ml_quit in case quit was not explicitly requested already. */ fs_ml_quit(); g_fs_emu_emulation_thread_running = 0; /* With this set, and fs_ml_quit being called, the frame render * function will call fs_ml_stop when the fadeout effect is done. */ g_fs_emu_emulation_thread_stopped = 1; return NULL; }
HRESULT ExecuteMain(ICLRRuntimeHost2* pCLRRuntimeHost, PCALL_APPLICATION_MAIN_DATA data, const std::wstring& runtime_directory, const std::wstring& core_clr_directory, dnx::trace_writer& trace_writer) { const wchar_t* property_keys[] = { // Allowed property names: // APPBASE // - The base path of the application from which the exe and other assemblies will be loaded L"APPBASE", // // TRUSTED_PLATFORM_ASSEMBLIES // - The list of complete paths to each of the fully trusted assemblies L"TRUSTED_PLATFORM_ASSEMBLIES", // // APP_PATHS // - The list of paths which will be probed by the assembly loader L"APP_PATHS", // // APP_NI_PATHS // - The list of additional paths that the assembly loader will probe for ngen images // // NATIVE_DLL_SEARCH_DIRECTORIES // - The list of paths that will be probed for native DLLs called by PInvoke // L"AppDomainCompatSwitch", }; std::wstring trusted_platform_assemblies; // Came up with 8192 empirically - the string we build is about 4000 characters on my machine but it contains // paths to the user profile folder so it can be bigger. trusted_platform_assemblies.reserve(8192); // Try native images first if (!GetTrustedPlatformAssembliesList(core_clr_directory, true, trusted_platform_assemblies)) { if (!GetTrustedPlatformAssembliesList(core_clr_directory, false, trusted_platform_assemblies)) { trace_writer.write(L"Failed to find TPA files in the coreclr directory", false); return E_FAIL; } } // Add the assembly containing the app domain manager to the trusted list trusted_platform_assemblies.append(dnx::utils::path_combine(runtime_directory, L"Microsoft.Dnx.Host.CoreClr.dll")); std::wstring app_paths; app_paths.append(runtime_directory).append(L";"); app_paths.append(core_clr_directory).append(L";"); const wchar_t* property_values[] = { // APPBASE data->applicationBase, // TRUSTED_PLATFORM_ASSEMBLIES trusted_platform_assemblies.c_str(), // APP_PATHS app_paths.c_str(), // Use the latest behavior when TFM not specified L"UseLatestBehaviorWhenTFMNotSpecified", }; DWORD domainId; HRESULT hr = pCLRRuntimeHost->CreateAppDomainWithManager( L"Microsoft.Dnx.Host.CoreClr", APPDOMAIN_ENABLE_PLATFORM_SPECIFIC_APPS | APPDOMAIN_ENABLE_PINVOKE_AND_CLASSIC_COMINTEROP | APPDOMAIN_DISABLE_TRANSPARENCY_ENFORCEMENT, NULL, NULL, sizeof(property_keys) / sizeof(wchar_t*), property_keys, property_values, &domainId); if (FAILED(hr)) { trace_writer.write(L"Failed to create app domain", false); trace_writer.write(std::wstring(L"TPA: ").append(trusted_platform_assemblies), false); trace_writer.write(std::wstring(L"AppPaths: ").append(app_paths), false); return hr; } HostMain main_function; // looks like the Version in the assembly is mandatory but the value does not matter hr = pCLRRuntimeHost->CreateDelegate(domainId, L"Microsoft.Dnx.Host.CoreClr, Version=0.0.0.0", L"DomainManager", L"Execute", (INT_PTR*)&main_function); if (FAILED(hr)) { trace_writer.write(L"Failed to create main delegate", false); return hr; } // Call main data->exitcode = main_function(data->argc, data->argv); pCLRRuntimeHost->UnloadAppDomain(domainId, true); return S_OK; }
const int Subcommand::operator()(int argc, char** argv) const { return main_function(argc, argv); }
/////////////////////////////////////////////////////////////////////////////// // Main program /////////////////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { char const* filename; if (argc > 1) { filename = argv[1]; } else { std::cerr << "Error: No input file provided." << std::endl; return 1; } std::ifstream in(filename, std::ios_base::in); if (!in) { std::cerr << "Error: Could not open input file: " << filename << std::endl; return 1; } std::string source_code; // We will read the contents here. in.unsetf(std::ios::skipws); // No white space skipping! std::copy( std::istream_iterator<char>(in), std::istream_iterator<char>(), std::back_inserter(source_code)); typedef std::string::const_iterator base_iterator_type; typedef client::lexer::conjure_tokens<base_iterator_type> lexer_type; typedef lexer_type::iterator_type iterator_type; lexer_type lexer; // Our lexer base_iterator_type first = source_code.begin(); base_iterator_type last = source_code.end(); iterator_type iter = lexer.begin(first, last); iterator_type end = lexer.end(); client::vmachine vm; // Our virtual machine client::ast::function_list ast; // Our AST client::error_handler<base_iterator_type, iterator_type> error_handler(first, last); // Our error handler client::parser::function<iterator_type, lexer_type> function(error_handler, lexer); // Our parser client::code_gen::compiler compiler(vm, error_handler); // Our compiler // note: we don't need a skipper bool success = parse(iter, end, +function, ast); std::cout << "-------------------------\n"; if (success && iter == end) { if (compiler(ast)) { // JIT the main function client::function main_function = vm.get_function("main"); if (!main_function) { std::cerr << "function main not found" << std::endl; return 1; } int nargs = argc-2; if (main_function.arity() != nargs) { std::cerr << "Error: main function requires " << main_function.arity() << " arguments." << std::endl; std::cerr << nargs << " supplied." << std::endl; return 1; } std::cout << "Success\n"; std::cout << "-------------------------\n"; std::cout << "Assembler----------------\n\n"; vm.print_assembler(); // Call the main function int r; char** args = argv + 2; switch (nargs) { case 0: r = main_function(); break; case 1: r = main_function( boost::lexical_cast<int>(args[0])); break; case 2: r = main_function( boost::lexical_cast<int>(args[0]), boost::lexical_cast<int>(args[1])); break; case 3: r = main_function( boost::lexical_cast<int>(args[0]), boost::lexical_cast<int>(args[1]), boost::lexical_cast<int>(args[2])); break; default: std::cerr << "Function calls with more " << "than 3 arguments not supported" << std::endl; return 1; } std::cout << "-------------------------\n"; std::cout << "Result: " << r << std::endl; std::cout << "-------------------------\n\n"; } else { std::cout << "Compile failure\n"; } } else { std::cout << "Parse failure\n"; } return 0; }
int main() { clock_t start,finish; double duration; int ret = 0; int one_size=320; char* file_name=malloc(50*sizeof(char)); file_name=strcpy(file_name,"test.xml"); char * xpath_name=malloc(50*sizeof(char)); xpath_name=strcpy(xpath_name,"XPath.txt"); printf("Welcome to the XML lexer program! Your file name is test.xml\n\n"); printf("begin to load the file\n"); start=clock(); int n=load_file(file_name); //load file into memory printf("finish loading the file. \n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for loading the file is %lf\n",duration); sleep(1); if(n==-1) { printf("There are something wrong with the xml file, we can not load it. Please check whether it is placed in the right place."); exit(1); } printf("begin to deal with XML file\n"); start=clock(); char* xmlPath="/company/develop/programmer"; xmlPath=ReadXPath(xpath_name); if(strcmp(xmlPath,"error")==0) { printf("There are something wrong with the XPath file, we can not load it. Please check whether it is placed in the right place."); exit(1); } createAutoMachine(xmlPath); //create auto machine by xmlpath printf("The basic structure of the automata is (from to end):\n"); int i,rc; char *out=" is an output"; for(i=1;i<=machineCount;i=i+2) { if(i==1){ printf("%d",stateMachine[i].start); } printf(" (str:%s",stateMachine[i].str); if(stateMachine[i].isoutput==1) { printf("%s",out); } printf(") %d",stateMachine[i].end); } printf("\n"); for(i=machineCount;i>0;i=i-2) { if(i==machineCount){ printf("%d (str:%s) %d",stateMachine[i].start,stateMachine[i].str,stateMachine[i].end); } else { printf(" (str:%s) %d",stateMachine[i].str,stateMachine[i].end); } } printf("\n\n"); main_function(); printf("finish dealing with the file\n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for dealing with the file is %lf\n",duration); printf("\n"); printf("All the subthread ended, now the program is merging its results.\n"); printf("begin to merge results\n"); start=clock(); ResultSet set=getresult(n); printf("The mappings for text.xml is:\n"); print_result(set); printf("finish merging these results\n"); finish=clock(); duration=(double)(finish-start)/CLOCKS_PER_SEC; printf("The duration for merging these results is %lf\n",duration); system("pause"); return 0; }
// Runs a PEACH query against a table. // // message - The message. // table - The table to run the query against. // output - The output stream to write to. // // Returns 0 if successful, otherwise returns -1. int sky_peach_message_process(sky_peach_message *message, sky_table *table, FILE *output) { int rc; check(message != NULL, "Message required"); check(table != NULL, "Table required"); check(output != NULL, "Output stream required"); // Compile. sky_qip_module *module = sky_qip_module_create(); check_mem(module); module->table = table; rc = sky_qip_module_compile(module, message->query); check(rc == 0, "Unable to compile query"); sky_qip_path_map_func main_function = (sky_qip_path_map_func)module->main_function; // Initialize the path iterator. sky_path_iterator iterator; sky_path_iterator_init(&iterator); rc = sky_path_iterator_set_data_file(&iterator, table->data_file); check(rc == 0, "Unable to initialze path iterator"); // Initialize QIP args. sky_qip_path *path = sky_qip_path_create(); qip_map *map = qip_map_create(); // Iterate over each path. uint32_t path_count = 0; while(!iterator.eof) { // Retrieve the path pointer. rc = sky_path_iterator_get_ptr(&iterator, &path->path_ptr); check(rc == 0, "Unable to retrieve the path iterator pointer"); // Execute query. main_function(path, map); // Move to next path. rc = sky_path_iterator_next(&iterator); check(rc == 0, "Unable to find next path"); path_count++; } //debug("Paths processed: %d", path_count); // Retrieve Result serialization function. struct tagbstring result_str = bsStatic("Result"); struct tagbstring serialize_str = bsStatic("serialize"); sky_qip_result_serialize_func result_serialize = NULL; rc = qip_module_get_class_method(module->_qip_module, &result_str, &serialize_str, (void*)(&result_serialize)); check(rc == 0 && result_serialize != NULL, "Unable to find serialize() method on class 'Result'"); // Serialize. qip_serializer *serializer = qip_serializer_create(); qip_serializer_pack_map(module->_qip_module, serializer, map->count); int64_t i; for(i=0; i<map->count; i++) { result_serialize(map->elements[i], serializer); } // Send response to output stream. rc = fwrite(serializer->data, serializer->length, 1, output); check(rc == 1, "Unable to write serialized data to stream"); qip_map_free(map); sky_qip_module_free(module); return 0; error: sky_qip_module_free(module); return -1; }