int main(int argc, char **argv) { pthread_t tid[NUMT]; int i; int error; (void)argc; /* we don't use any arguments in this example */ (void)argv; /* Must initialize libcurl before any threads are started */ curl_global_init(CURL_GLOBAL_ALL); init_locks(); for(i=0; i< NUMT; i++) { error = pthread_create(&tid[i], NULL, /* default attributes please */ pull_one_url, (void *)urls[i]); if(0 != error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); } /* now wait for all threads to terminate */ for(i=0; i< NUMT; i++) { error = pthread_join(tid[i], NULL); fprintf(stderr, "Thread %d terminated\n", i); } kill_locks(); return 0; }
int main (int argc, char *argv[]) { unsigned threads = 2; Option.numthreads = 2; punyopt(argc, argv, myopt, "k:"); Loops = Option.iterations; threads = Option.numthreads; if (!threads) { fatal("Must have at least one thread"); } if (threads >= Num_locks) { fatal("Must have at least one more locks(%ld) than threads(%d)", Num_locks, threads); } init_locks(Num_locks); #if MUTEX printf("pthread mutex\n"); #elif SPIN printf("raw spinlock\n"); #elif TSPIN printf("pthread spinlock\n"); #elif GLOBAL printf("global variable\n"); #else printf("Empty test\n"); #endif start_threads(threads); return 0; }
int main(int argc, char **argv) { pthread_t tid[NUMT]; int error; curl_global_init(CURL_GLOBAL_ALL); init_locks(); for (int i = 0; i < NUMT; i++) { error = pthread_create(&tid[i], NULL, pull_one_url, (void *)urls[i]); if (0 != error) fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); else fprintf(stderr, "Thread %d, gets %s\n", i, urls[i]); } for (int i = 0; i < NUMT; i++) { error = pthread_join(tid[i], NULL); fprintf(stderr, "Thread %d terminated\n", i); } kill_locks(); return 0; }
/* * Functionality for pthread_create() */ int mypthread_create(mypthread_t *thread, const mypthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { if (mypthread_count == 0) { //mypthread_create was called for the first time //Init locks that is going to be used by the entire thread library init_locks(); //Creating a thread for calling thread (assuming it is main function) main_thread.th_id = ++mypthread_th_gen; mypthread_count++; main_thread.ctx = (ucontext_t*) malloc(sizeof(ucontext_t)); main_thread.ctx->uc_stack.ss_sp = (char*) malloc(sizeof(char) * 4096); main_thread.ctx->uc_stack.ss_size = 4096; main_thread.state = PS_RUNNING; //Insert into kthread mykthread_t* k_th = (mykthread_t *) malloc(sizeof(mykthread_t)); k_th->kth_id = gettid(); k_th->th = &main_thread; //Add to the kthread list sem_wait(&kthread_sem); //Assuming initially there will be only one kthread current_kthread_count = 1; mykthread_add(k_th); sem_post(&kthread_sem); } // Create node for thread ucontext_t* context = (ucontext_t*) malloc(sizeof(ucontext_t)); thread->ctx = context; getcontext(thread->ctx); (*thread).ctx->uc_stack.ss_sp = (char*) malloc(sizeof(char) * 4096); (*thread).ctx->uc_stack.ss_size = 4096; (*thread).state = PS_ACTIVE; makecontext(thread->ctx, (void (*)()) start_routine, 1, arg); sem_wait(&mypthread_sem); thread->th_id = ++mypthread_th_gen; mypthread_count++; mypthread_enqueue(thread); sem_post(&mypthread_sem); //Create new kthread bool create_thread_flag; //Create Kthread as per Pthread library policy if (mypthread_policy == KLMATCHCORES || mypthread_policy == KLMATCHHYPER) { sem_wait(&kthread_sem); create_thread_flag = false; if (current_kthread_count < max_kthread_count) { current_kthread_count++; create_thread_flag = true; } sem_post(&kthread_sem); if (create_thread_flag) { create_kthread(); } } else if (mypthread_policy == KLALWAYS) { sem_wait(&kthread_sem); current_kthread_count++; sem_post(&kthread_sem); create_kthread(); } return 0; }
void prvHardwareSetup(void) { // set GPIO direction init_gpio(); // create mutex and semaphore init_locks(); // enable interrupt for sensors init_sensor(); }
int cloudfs_connect(char *username, char *password, char *authurl, int use_snet) { static struct { char username[MAX_HEADER_SIZE], password[MAX_HEADER_SIZE], authurl[MAX_URL_SIZE], use_snet; } reconnect_args; long response = -1; static int initialized = 0; if (!initialized) { LIBXML_TEST_VERSION init_locks(); curl_global_init(CURL_GLOBAL_ALL); strncpy(reconnect_args.username, username, sizeof(reconnect_args.username)); strncpy(reconnect_args.password, password, sizeof(reconnect_args.password)); strncpy(reconnect_args.authurl, authurl, sizeof(reconnect_args.authurl)); reconnect_args.use_snet = use_snet; initialized = 1; } else { username = reconnect_args.username; password = reconnect_args.password; authurl = reconnect_args.authurl; use_snet = reconnect_args.use_snet; } pthread_mutex_lock(&pool_mut); debugf("Authenticating..."); storage_token[0] = storage_url[0] = '\0'; curl_slist *headers = NULL; add_header(&headers, "X-Auth-User", username); add_header(&headers, "X-Auth-Key", password); CURL *curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_VERBOSE, debug); curl_easy_setopt(curl, CURLOPT_URL, authurl); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, &header_dispatch); curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_perform(curl); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response); curl_slist_free_all(headers); curl_easy_cleanup(curl); if (use_snet && storage_url[0]) rewrite_url_snet(storage_url); pthread_mutex_unlock(&pool_mut); return (response >= 200 && response < 300 && storage_token[0] && storage_url[0]); }
TInt Open(RSocketServ& aServer,const TDesC& aName) { TInt err = init_locks(); if (err != KErrNone) { return err; } err = RSocket::Open(aServer, aName); if (err != KErrNone) { destroy_locks(); } return err; }
void prvHardwareSetup(void) { // init shard_buf volatile unsigned long *addr = IO_TYPE; *addr = EMPTY_REQ; // set GPIO direction init_gpio(); // create mutex and semaphore init_locks(); // enable interrupt for sensors init_sensor(); }
//读取子图文件,还原一个子图 //1 void Subgraph::recover(string name,string dir){ graph_dir=dir; filename=name; sub_key=get_sub_key(name,dir); io.open(filename.c_str(),fstream::out|fstream::in|ios::binary); io.seekg(0); io.read((char*)&head,sizeof(SubgraphHeader));//读取子图文件中的子图头,这部分数据要事先读入内存 first=last=NULL;//内存缓冲区是0 init_locks(); delete_count=0; vertex_index.recover(graph_dir+"/"+sub_key+"_"+getenv("VERTEX_INDEX_FILENAME"));//还原顶点索引 }
TInt Open(RSocketServ& aServer) { TInt err = init_locks(); if (err != KErrNone) { return err; } err = RSocket::Open(aServer); if (err != KErrNone) { destroy_locks(); } return err; }
TInt Open(RSocketServ& aServer, TUint addrFamily, TUint sockType, TUint protocol) { TInt err = init_locks(); if (err != KErrNone) { return err; } err = RSocket::Open(aServer, addrFamily, sockType, protocol); if (err != KErrNone) { destroy_locks(); } return err; }
//新建一个子图文件(子图文件存在,则会被清零),初始化为默认的大小(操作系统的栈大小要调整,否则会段错误) //返回0表示成功,返回1表示失败 //1 int Subgraph::init(string name,string dir){ //文件存在则清零,不存在则创建 filename=name; io.open(filename.c_str(),fstream::out|fstream::in|ios::binary|fstream::trunc); if(!io){ cout<<"subgraph "<<name<<" create failed"<<endl; return 1; } graph_dir=dir; sub_key=get_sub_key(name,dir); first=last=NULL;//内存的缓冲区块链表为空 delete_count=0; //初始化默认大小 init_locks(); return 0; }
int init_dsm_page_ownership (int number_of_owners, int number_of_pages, int my_id) { int r; nowners = number_of_owners; npages = number_of_pages; thisid = my_id; if ((r = init_page_statuses()) < 0) { return r; } if ((r = init_locks()) < 0) { return r; } if ((r = init_waits()) < 0) { return r; } return 0; }
int main(int argc, char *argv[]) { // rand int seed if(argc != 3) { printf("Usage :\n> ./MMU X Y\nX -> Type of eviction algorithm\nY -> 1 for metrics, 2 for debugging\n"); return -1; } srand((unsigned int)time(NULL)); type_r = atoi(argv[1]); struct timeval tvalBefore, tvalAfter; if((printing =atoi(argv[2])) > 0) { gettimeofday(&tvalBefore, NULL); } // Initialize locks and free virtual memory addresses init_locks(); init_memory(); for(int i = 0; i < NUMTHREADS; i++) { thread_identifiers[i] = i; pthread_create(&tests[i], NULL, (void *) &test_thread, (void *) &(thread_identifiers[i])); } for(int i = 0; i < NUMTHREADS; i++) { pthread_join(tests[i], NULL); } for(int i = 0; i < MAXADDR; i++) { if(page_table[i].empty == 0){ free_page(i); } } if(printing > 0) { gettimeofday(&tvalAfter, NULL); printf("Time in microseconds: %ld\n", ((tvalAfter.tv_sec - tvalBefore.tv_sec)*1000000L +tvalAfter.tv_usec) - tvalBefore.tv_usec ); printf("Number of SSD faults: %d\n", ssd_faults); printf("Number of HDD faults: %d\n", hdd_faults); } }
int biterc_newsession(const char *tmpdir, size_t shm_size) { biterc_session_t *session = NULL; int biter_session; int result; if (biter_cur_session >= BITER_MAX_SESSIONS) { biter_lasterror = "Exceeded maximum number of sessions"; goto error; } biter_session = biter_cur_session++; session = sessions + biter_session; result = init_shm(tmpdir, shm_size, session); if (result == -1) goto error; result = init_locks(session); if (result == -1) goto error; result = setup_ids(session); if (result == -1) goto error; result = biter_connect(tmpdir, session); if (result == -1) goto error; result = init_heap(session); if (result == -1) goto error; return biter_session; error: return -1; }
void KICAD_CURL::Init() { // We test s_initialized twice in an effort to avoid // unnecessarily locking s_lock. This understands that the common case // will not need to lock. if( !s_initialized ) { MUTLOCK lock( s_lock ); if( !s_initialized ) { if( curl_global_init( CURL_GLOBAL_ALL ) != CURLE_OK ) { THROW_IO_ERROR( "curl_global_init() failed." ); } init_locks(); wxLogDebug( "Using %s", GetVersion() ); s_initialized = true; } } }
/** * * Initializes threads. If this function is not called, the D-Bus * library will not lock any data structures. If it is called, D-Bus * will do locking, at some cost in efficiency. Note that this * function must be called BEFORE the second thread is started. * * Almost always, you should use dbus_threads_init_default() instead. * The raw dbus_threads_init() is only useful if you require a * particular thread implementation for some reason. * * A possible reason to use dbus_threads_init() rather than * dbus_threads_init_default() is to insert debugging checks or print * statements. * * dbus_threads_init() may be called more than once. The first one * wins and subsequent calls are ignored. (Unless you use * dbus_shutdown() to reset libdbus, which will let you re-init * threads.) * * Either recursive or nonrecursive mutex functions must be specified, * but not both. New code should provide only the recursive functions * - specifying the nonrecursive ones is deprecated. * * Because this function effectively sets global state, all code * running in a given application must agree on the thread * implementation. Most code won't care which thread implementation is * used, so there's no problem. However, usually libraries should not * call dbus_threads_init() or dbus_threads_init_default(), instead * leaving this policy choice to applications. * * The exception is for application frameworks (GLib, Qt, etc.) and * D-Bus bindings based on application frameworks. These frameworks * define a cross-platform thread abstraction and can assume * applications using the framework are OK with using that thread * abstraction. * * However, even these app frameworks may find it easier to simply call * dbus_threads_init_default(), and there's no reason they shouldn't. * * @param functions functions for using threads * @returns #TRUE on success, #FALSE if no memory */ dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions) { dbus_bool_t mutex_set; dbus_bool_t recursive_mutex_set; _dbus_assert (functions != NULL); /* these base functions are required. Future additions to * DBusThreadFunctions may be optional. */ _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK); _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK); _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK); _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK); _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK); _dbus_assert (functions->mask & DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK); _dbus_assert (functions->condvar_new != NULL); _dbus_assert (functions->condvar_free != NULL); _dbus_assert (functions->condvar_wait != NULL); _dbus_assert (functions->condvar_wait_timeout != NULL); _dbus_assert (functions->condvar_wake_one != NULL); _dbus_assert (functions->condvar_wake_all != NULL); /* Either the mutex function set or recursive mutex set needs * to be available but not both */ mutex_set = (functions->mask & DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK) && functions->mutex_new && functions->mutex_free && functions->mutex_lock && functions->mutex_unlock; recursive_mutex_set = (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK) && (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK) && functions->recursive_mutex_new && functions->recursive_mutex_free && functions->recursive_mutex_lock && functions->recursive_mutex_unlock; if (!(mutex_set || recursive_mutex_set)) _dbus_assert_not_reached ("Either the nonrecusrive or recursive mutex " "functions sets should be passed into " "dbus_threads_init. Neither sets were passed."); if (mutex_set && recursive_mutex_set) _dbus_assert_not_reached ("Either the nonrecusrive or recursive mutex " "functions sets should be passed into " "dbus_threads_init. Both sets were passed. " "You most likely just want to set the recursive " "mutex functions to avoid deadlocks in D-Bus."); /* Check that all bits in the mask actually are valid mask bits. * ensures people won't write code that breaks when we add * new bits. */ _dbus_assert ((functions->mask & ~DBUS_THREAD_FUNCTIONS_ALL_MASK) == 0); if (thread_init_generation != _dbus_current_generation) thread_functions.mask = 0; /* allow re-init in new generation */ /* Silently allow multiple init * First init wins and D-Bus will always use its threading system */ if (thread_functions.mask != 0) return TRUE; thread_functions.mutex_new = functions->mutex_new; thread_functions.mutex_free = functions->mutex_free; thread_functions.mutex_lock = functions->mutex_lock; thread_functions.mutex_unlock = functions->mutex_unlock; thread_functions.condvar_new = functions->condvar_new; thread_functions.condvar_free = functions->condvar_free; thread_functions.condvar_wait = functions->condvar_wait; thread_functions.condvar_wait_timeout = functions->condvar_wait_timeout; thread_functions.condvar_wake_one = functions->condvar_wake_one; thread_functions.condvar_wake_all = functions->condvar_wake_all; if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK) thread_functions.recursive_mutex_new = functions->recursive_mutex_new; if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK) thread_functions.recursive_mutex_free = functions->recursive_mutex_free; if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK) thread_functions.recursive_mutex_lock = functions->recursive_mutex_lock; if (functions->mask & DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK) thread_functions.recursive_mutex_unlock = functions->recursive_mutex_unlock; thread_functions.mask = functions->mask; if (!init_locks ()) return FALSE; thread_init_generation = _dbus_current_generation; return TRUE; }
// ---------------------------------------------------------------------------- int main (int argc, char** argv) { gchar* string; gint ipc_status; // I18N #ifdef LOCALEDIR bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); #else string = g_build_filename (ug_get_data_dir (), "locale", NULL); bindtextdomain (GETTEXT_PACKAGE, string); g_free (string); #endif bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifdef USE_GNUTLS init_locks (); #endif string = ug_arg_find_version (argc, argv); if (string) { #if defined (_WIN32) && defined (_WINDOWS) win32_console_init (); #endif // _WIN32 && _WINDOWS g_print ("uGet " PACKAGE_VERSION " for GTK+" "\n"); return EXIT_SUCCESS; } string = ug_arg_find_help (argc, argv); // initialize for MS-Windows #if defined (_WIN32) #if defined (_WINDOWS) if (string) win32_console_init (); #endif // _WINDOWS win32_winsock_init (); #endif // _WIN32 // uglib: options app = g_slice_alloc0 (sizeof (UgAppGtk)); ug_option_init (&app->option); ug_option_add (&app->option, NULL, gtk_get_option_group (TRUE)); if (string) { g_print ("uGet " PACKAGE_VERSION " for GTK+" "\n"); ug_option_help (&app->option, argv[0], string); } // GTK+ gtk_init (&argc, &argv); // GStreamer #ifdef HAVE_GSTREAMER gst_inited = gst_init_check (&argc, &argv, NULL); #endif // IPC initialize & check exist Uget program ipc_status = ug_ipc_init_with_args (&app->ipc, argc, argv); if (ipc_status < 1) { if (ipc_status == -1) g_print ("uget: IPC failed.\n"); // if (ipc_status == 0) // g_print ("uget: Server exists.\n"); ug_ipc_finalize (&app->ipc); goto exit; } // libnotify #ifdef HAVE_LIBNOTIFY notify_init ("uGet"); #endif // register uget interfaces uglib_init (); // main program ug_app_init (app); signal (SIGTERM, term_signal_handler); gtk_main (); // libnotify #ifdef HAVE_LIBNOTIFY if (notify_is_initted ()) notify_uninit (); #endif // shutdown IPC and sleep 3 second to wait thread g_usleep (3 * 1000000); ug_ipc_finalize (&app->ipc); exit: // finalize for MS-Windows #ifdef _WIN32 win32_winsock_finalize (); #endif return EXIT_SUCCESS; }
static void init(struct fmt_main *self) { #ifdef CL_VERSION_1_0 char *temp; cl_ulong maxsize; global_work_size = 0; opencl_init("$JOHN/rar_kernel.cl", ocl_gpu_id, platform_id); // create kernel to execute crypt_kernel = clCreateKernel(program[ocl_gpu_id], "SetCryptKeys", &ret_code); HANDLE_CLERROR(ret_code, "Error creating kernel. Double-check kernel name?"); /* We mimic the lengths of cRARk for comparisons */ if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_GPU) { #ifndef DEBUG self->params.benchmark_comment = " (6 characters)"; #endif self->params.tests = gpu_tests; #if defined(DEBUG) && !defined(ALWAYS_OPENCL) fprintf(stderr, "Note: will use CPU for some self-tests, and Single mode.\n"); #endif } if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, LWS_CONFIG))) local_work_size = atoi(temp); if ((temp = cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, GWS_CONFIG))) global_work_size = atoi(temp); if ((temp = getenv("LWS"))) local_work_size = atoi(temp); if ((temp = getenv("GWS"))) global_work_size = atoi(temp); /* Note: we ask for this kernel's max size, not the device's! */ HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_WORK_GROUP_SIZE, sizeof(maxsize), &maxsize, NULL), "Query max work group size"); #ifdef DEBUG fprintf(stderr, "Max allowed local work size %d\n", (int)maxsize); #endif if (!local_work_size) { if (get_device_type(ocl_gpu_id) == CL_DEVICE_TYPE_CPU) { if (get_platform_vendor_id(platform_id) == INTEL) local_work_size = 8; else local_work_size = 1; } else { local_work_size = 64; } } if (local_work_size > maxsize) { fprintf(stderr, "LWS %d is too large for this GPU. Max allowed is %d, using that.\n", (int)local_work_size, (int)maxsize); local_work_size = maxsize; } if (!global_work_size) find_best_gws(temp == NULL ? 0 : 1); if (global_work_size < local_work_size) global_work_size = local_work_size; fprintf(stderr, "Local worksize (LWS) %d, Global worksize (GWS) %d\n", (int)local_work_size, (int)global_work_size); create_clobj(global_work_size); #ifdef DEBUG { cl_ulong loc_mem_size; HANDLE_CLERROR(clGetKernelWorkGroupInfo(crypt_kernel, devices[ocl_gpu_id], CL_KERNEL_LOCAL_MEM_SIZE, sizeof(loc_mem_size), &loc_mem_size, NULL), "Query local memory usage"); fprintf(stderr, "Kernel using %lu bytes of local memory out of %lu available\n", loc_mem_size, get_local_memory_size(ocl_gpu_id)); } #endif atexit(release_clobj); *mkpc = VF * global_work_size; #endif /* OpenCL */ #if defined (_OPENMP) omp_t = omp_get_max_threads(); self->params.min_keys_per_crypt *= omp_t; #ifndef CL_VERSION_1_0 /* OpenCL gets to decide */ *mkpc = omp_t * OMP_SCALE * MAX_KEYS_PER_CRYPT; #endif init_locks(); #endif /* _OPENMP */ if (options.utf8) self->params.plaintext_length = PLAINTEXT_LENGTH * 3; unpack_data = mem_calloc_tiny(sizeof(unpack_data_t) * omp_t, MEM_ALIGN_WORD); cracked = mem_calloc_tiny(sizeof(*cracked) * *mkpc, MEM_ALIGN_WORD); #ifndef CL_VERSION_1_0 saved_key = mem_calloc_tiny(UNICODE_LENGTH * *mkpc, MEM_ALIGN_NONE); saved_len = mem_calloc_tiny(sizeof(*saved_len) * *mkpc, MEM_ALIGN_WORD); saved_salt = mem_calloc_tiny(8, MEM_ALIGN_NONE); aes_key = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE); aes_iv = mem_calloc_tiny(16 * *mkpc, MEM_ALIGN_NONE); #endif /* OpenSSL init */ init_aesni(); SSL_load_error_strings(); SSL_library_init(); OpenSSL_add_all_algorithms(); #ifndef __APPLE__ atexit(openssl_cleanup); #endif /* CRC-32 table init, do it before we start multithreading */ { CRC32_t crc; CRC32_Init(&crc); } }
int main(int argc, char *argv[]) { int step, ie, iside, i, j, k; double mflops, tmax, nelt_tot = 0.0; char Class; logical ifmortar = false, verified; double t2, trecs[t_last+1]; char *t_names[t_last+1]; //-------------------------------------------------------------------- // Initialize NUMA control //-------------------------------------------------------------------- numa_initialize_env(NUMA_MIGRATE_EXISTING); //--------------------------------------------------------------------- // Read input file (if it exists), else take // defaults from parameters //--------------------------------------------------------------------- FILE *fp; if ((fp = fopen("timer.flag", "r")) != NULL) { timeron = true; t_names[t_total] = "total"; t_names[t_init] = "init"; t_names[t_convect] = "convect"; t_names[t_transfb_c] = "transfb_c"; t_names[t_diffusion] = "diffusion"; t_names[t_transf] = "transf"; t_names[t_transfb] = "transfb"; t_names[t_adaptation] = "adaptation"; t_names[t_transf2] = "transf+b"; t_names[t_add2] = "add2"; fclose(fp); } else { timeron = false; } printf("\n\n NAS Parallel Benchmarks (NPB3.3-OMP-C) - UA Benchmark\n\n"); if ((fp = fopen("inputua.data", "r")) != NULL) { int result; printf(" Reading from input file inputua.data\n"); result = fscanf(fp, "%d", &fre); while (fgetc(fp) != '\n'); result = fscanf(fp, "%d", &niter); while (fgetc(fp) != '\n'); result = fscanf(fp, "%d", &nmxh); while (fgetc(fp) != '\n'); result = fscanf(fp, "%lf", &alpha); Class = 'U'; fclose(fp); } else { printf(" No input file inputua.data. Using compiled defaults\n"); fre = FRE_DEFAULT; niter = NITER_DEFAULT; nmxh = NMXH_DEFAULT; alpha = ALPHA_DEFAULT; Class = CLASS_DEFAULT; } dlmin = pow(0.5, REFINE_MAX); dtime = 0.04*dlmin; printf(" Levels of refinement: %8d\n", REFINE_MAX); printf(" Adaptation frequency: %8d\n", fre); printf(" Time steps: %8d dt: %15.6E\n", niter, dtime); printf(" CG iterations: %8d\n", nmxh); printf(" Heat source radius: %8.4f\n", alpha); printf(" Number of available threads: %8d\n", omp_get_max_threads()); printf("\n"); top_constants(); for (i = 1; i <= t_last; i++) { timer_clear(i); } if (timeron) timer_start(t_init); // set up initial mesh (single element) and solution (all zero) create_initial_grid(); r_init_omp((double *)ta1, ntot, 0.0); nr_init_omp((int *)sje, 4*6*nelt, -1); init_locks(); // compute tables of coefficients and weights coef(); geom1(); // compute the discrete laplacian operators setdef(); // prepare for the preconditioner setpcmo_pre(); // refine initial mesh and do some preliminary work time = 0.0; mortar(); prepwork(); adaptation(&ifmortar, 0); if (timeron) timer_stop(t_init); timer_clear(1); time = 0.0; for (step = 0; step <= niter; step++) { if (step == 1) { // reset the solution and start the timer, keep track of total no elms r_init((double *)ta1, ntot, 0.0); time = 0.0; nelt_tot = 0.0; for (i = 1; i <= t_last; i++) { if (i != t_init) timer_clear(i); } timer_start(1); } // advance the convection step convect(ifmortar); if (timeron) timer_start(t_transf2); // prepare the intital guess for cg transf(tmort, (double *)ta1); // compute residual for diffusion term based on intital guess // compute the left hand side of equation, lapacian t #pragma omp parallel default(shared) private(ie,k,j,i) { #pragma omp for for (ie = 0; ie < nelt; ie++) { laplacian(ta2[ie], ta1[ie], size_e[ie]); } // compute the residual #pragma omp for for (ie = 0; ie < nelt; ie++) { for (k = 0; k < LX1; k++) { for (j = 0; j < LX1; j++) { for (i = 0; i < LX1; i++) { trhs[ie][k][j][i] = trhs[ie][k][j][i] - ta2[ie][k][j][i]; } } } } } //end parallel // get the residual on mortar transfb(rmor, (double *)trhs); if (timeron) timer_stop(t_transf2); // apply boundary condition: zero out the residual on domain boundaries // apply boundary conidtion to trhs #pragma omp parallel for default(shared) private(ie,iside) for (ie = 0; ie < nelt; ie++) { for (iside = 0; iside < NSIDES; iside++) { if (cbc[ie][iside] == 0) { facev(trhs[ie], iside, 0.0); } } } // apply boundary condition to rmor col2(rmor, tmmor, nmor); // call the conjugate gradient iterative solver diffusion(ifmortar); // add convection and diffusion if (timeron) timer_start(t_add2); add2((double *)ta1, (double *)t, ntot); if (timeron) timer_stop(t_add2); // perform mesh adaptation time = time + dtime; if ((step != 0) && (step/fre*fre == step)) { if (step != niter) { adaptation(&ifmortar, step); } } else { ifmortar = false; } nelt_tot = nelt_tot + (double)(nelt); } timer_stop(1); tmax = timer_read(1); verify(&Class, &verified); // compute millions of collocation points advanced per second. // diffusion: nmxh advancements, convection: 1 advancement mflops = nelt_tot*(double)(LX1*LX1*LX1*(nmxh+1))/(tmax*1.e6); print_results("UA", Class, REFINE_MAX, 0, 0, niter, tmax, mflops, " coll. point advanced", verified, NPBVERSION, COMPILETIME, CS1, CS2, CS3, CS4, CS5, CS6, "(none)"); //--------------------------------------------------------------------- // More timers //--------------------------------------------------------------------- if (timeron) { for (i = 1; i <= t_last; i++) { trecs[i] = timer_read(i); } if (tmax == 0.0) tmax = 1.0; printf(" SECTION Time (secs)\n"); for (i = 1; i <= t_last; i++) { printf(" %-10s:%9.3f (%6.2f%%)\n", t_names[i], trecs[i], trecs[i]*100./tmax); if (i == t_transfb_c) { t2 = trecs[t_convect] - trecs[t_transfb_c]; printf(" --> %11s:%9.3f (%6.2f%%)\n", "sub-convect", t2, t2*100./tmax); } else if (i == t_transfb) { t2 = trecs[t_diffusion] - trecs[t_transf] - trecs[t_transfb]; printf(" --> %11s:%9.3f (%6.2f%%)\n", "sub-diffuse", t2, t2*100./tmax); } } } //-------------------------------------------------------------------- // Teardown NUMA control //-------------------------------------------------------------------- numa_shutdown(); return 0; }
int main(int argc, char **argv) { memset(&global_info, 0, sizeof(global_info_t)); char *url = http_url; global_info.round = 1; int opt; while ((opt = getopt(argc, argv, "w:t:r:hs")) != -1) { switch (opt) { case 'w': global_info.work_num = atoi(optarg); break; case 't': global_info.thread_num = atoi(optarg); break; case 'r': global_info.round = atoi(optarg); break; case 's': url = https_url; break; case 'h': default: show_help(); return EXIT_SUCCESS; } } if (global_info.work_num == 0 || global_info.thread_num == 0) { show_help(); return EXIT_FAILURE; } setsignal(SIGINT, _sig_int); setsignal(SIGTERM, _sig_int); printf("get work num: %u, thread num: %u\n", global_info.work_num, global_info.thread_num); thread_info_t *thread_list = calloc(global_info.thread_num, sizeof(thread_info_t)); if (thread_list == NULL) { printf("alloc threads error\n"); return EXIT_FAILURE; } global_info.work_list = calloc(global_info.work_num, sizeof(work_info_t *)); if (global_info.work_list == NULL) { printf("alloc work_list error\n"); return EXIT_FAILURE; } int idx = 0; for (idx = 0; idx < global_info.work_num; ++idx) { global_info.work_list[idx] = calloc(1, sizeof(work_info_t)); if (global_info.work_list[idx] == NULL) { printf("alloc work_list %u error\n", idx); return EXIT_FAILURE; } global_info.work_list[idx]->url = url; global_info.work_list[idx]->idx = idx; } /* Must initialize libcurl before any threads are started */ curl_global_init(CURL_GLOBAL_ALL); init_locks(); TS_INIT(); mutexlock_init(global_info.rmtx); mutexlock_init(global_info.wmtx); TS_DECLARE(perf); for (idx = 0; idx < global_info.thread_num; ++idx) { thread_list[idx].global_info = &global_info; thread_list[idx].curl = curl_easy_init(); thread_list[idx].multi_handle = curl_multi_init(); if (thread_list[idx].curl == NULL || thread_list[idx].multi_handle == NULL) { printf("error when curl init\n"); return EXIT_FAILURE; } //curl_easy_setopt(thread_list[idx].curl, CURLOPT_FORBID_REUSE, 1L); curl_easy_setopt(thread_list[idx].curl, CURLOPT_NOSIGNAL, 1L); if (url == https_url) { curl_easy_setopt(thread_list[idx].curl, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(thread_list[idx].curl, CURLOPT_SSL_VERIFYHOST, 0L); } thread_list[idx].idx = idx; set_share_handle(thread_list[idx].curl); } int error; TS_BEGIN(perf); for (idx = 0; idx < global_info.thread_num; ++idx) { error = pthread_create(&(thread_list[idx].tid), NULL, /* default attributes please */ pull_one_url, (void *) & (thread_list[idx])); if (0 != error) { fprintf(stderr, "Couldn't run thread number %d, errno %d\n", idx, error); return EXIT_FAILURE; } } /* now wait for all threads to terminate */ for (idx = 0; idx < global_info.thread_num; idx++) { error = pthread_join(thread_list[idx].tid, NULL); //printf("[%u:%lu]Thread %d terminated\n", idx, time(NULL), idx); } TS_END(perf); for (idx = 0; idx < global_info.thread_num; idx++) { curl_easy_cleanup(thread_list[idx].curl); curl_multi_cleanup(thread_list[idx].multi_handle); } free(thread_list); unsigned long total_length = 0; for (idx = 0; idx < global_info.work_num; idx++) { if (global_info.work_list[idx]) { if (global_info.work_list[idx]->status == STAT_DONE) { total_length += global_info.work_list[idx]->data_len; } free(global_info.work_list[idx]); } } free(global_info.work_list); printf("RATE: worknum:%u total_length:%lu total_ms_diff:%lu, %.1fK\n", global_info.work_num, total_length, TS_MSDIFF(perf), (double)(total_length) / (double)(TS_MSDIFF(perf))); kill_locks(); curl_global_cleanup(); return EXIT_SUCCESS; }
int drngInit(JNIEnv *env) { char msg[1000]; int rc, ret; ENGINE* eng; #ifdef UNIX void *openssl = dlopen(HADOOP_CRYPTO_LIBRARY, RTLD_LAZY | RTLD_GLOBAL); #endif #ifdef WINDOWS HMODULE openssl = LoadLibrary(HADOOP_CRYPTO_LIBRARY); #endif if (!openssl) { snprintf(msg, sizeof(msg), "Cannot load %s!", HADOOP_CRYPTO_LIBRARY); THROW(env, "java/lang/UnsatisfiedLinkError", msg); return; } #ifdef UNIX dlerror(); // Clear any existing error LOAD_DYNAMIC_SYMBOL(dlsym_CRYPTO_malloc, env, openssl, "CRYPTO_malloc"); LOAD_DYNAMIC_SYMBOL(dlsym_CRYPTO_free, env, openssl, "CRYPTO_free"); LOAD_DYNAMIC_SYMBOL(dlsym_CRYPTO_num_locks, env, openssl, "CRYPTO_num_locks"); LOAD_DYNAMIC_SYMBOL(dlsym_CRYPTO_set_locking_callback, \ env, openssl, "CRYPTO_set_locking_callback"); LOAD_DYNAMIC_SYMBOL(dlsym_CRYPTO_set_id_callback, env, \ openssl, "CRYPTO_set_id_callback"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_load_rdrand, env, \ openssl, "ENGINE_load_rdrand"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_by_id, env, openssl, "ENGINE_by_id"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_init, env, openssl, "ENGINE_init"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_set_default, env, \ openssl, "ENGINE_set_default"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_finish, env, openssl, "ENGINE_finish"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_free, env, openssl, "ENGINE_free"); LOAD_DYNAMIC_SYMBOL(dlsym_ENGINE_cleanup, env, openssl, "ENGINE_cleanup"); LOAD_DYNAMIC_SYMBOL(dlsym_RAND_bytes, env, openssl, "RAND_bytes"); #endif #ifdef WINDOWS LOAD_DYNAMIC_SYMBOL(__dlsym_CRYPTO_malloc, dlsym_CRYPTO_malloc, \ env, openssl, "CRYPTO_malloc"); LOAD_DYNAMIC_SYMBOL(__dlsym_CRYPTO_free, dlsym_CRYPTO_free, \ env, openssl, "CRYPTO_free"); LOAD_DYNAMIC_SYMBOL(__dlsym_CRYPTO_num_locks, dlsym_CRYPTO_num_locks, \ env, openssl, "CRYPTO_num_locks"); LOAD_DYNAMIC_SYMBOL(__dlsym_CRYPTO_set_locking_callback, \ dlsym_CRYPTO_set_locking_callback, \ env, openssl, "CRYPTO_set_locking_callback"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_load_rdrand, dlsym_ENGINE_load_rdrand, \ env, openssl, "ENGINE_load_rdrand"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_by_id, dlsym_ENGINE_by_id, \ env, openssl, "ENGINE_by_id"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_init, dlsym_ENGINE_init, \ env, openssl, "ENGINE_init"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_set_default, dlsym_ENGINE_set_default, \ env, openssl, "ENGINE_set_default"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_finish, dlsym_ENGINE_finish, \ env, openssl, "ENGINE_finish"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_free, dlsym_ENGINE_free, \ env, openssl, "ENGINE_free"); LOAD_DYNAMIC_SYMBOL(__dlsym_ENGINE_cleanup, dlsym_ENGINE_cleanup, \ env, openssl, "ENGINE_cleanup"); LOAD_DYNAMIC_SYMBOL(__dlsym_RAND_bytes, dlsym_RAND_bytes, \ env, openssl, "RAND_bytes"); #endif init_locks(); dlsym_ENGINE_load_rdrand(); eng = dlsym_ENGINE_by_id("rdrand"); ret = -1; do { if (NULL == eng) { break; } rc = dlsym_ENGINE_init(eng); if (1 != rc) { break; } rc = dlsym_ENGINE_set_default(eng, ENGINE_METHOD_RAND); if(1 != rc) { break; } ret = 0; } while(0); if (ret == -1) { if (NULL != eng) { dlsym_ENGINE_finish(eng); dlsym_ENGINE_free(eng); } dlsym_ENGINE_cleanup(); destroy_locks(); } return ret; }
void InitCurl(){ curl_global_init(CURL_GLOBAL_ALL); #ifdef USE_OPENSSL init_locks(); #endif }