bool os::task_control_block::execute(const os::tick_type& timepoint_of_ckeck_ready_task) const { // Check for a task event. const bool task_does_have_event = (my_event != event_type(0U)); if(task_does_have_event) { // Set the global task index equal to the index of the running task. os_task_global_index() = my_index; // Call the task function because of an event. my_func(); } // Check for a task timeout. const bool task_does_have_timeout = ( (my_cycle != os::tick_type(0U)) && my_timer.timeout_of_specific_timepoint(timepoint_of_ckeck_ready_task)); if(task_does_have_timeout) { // Increment the task's interval timer with the task cycle. my_timer.start_interval(my_cycle); // Set the global task index equal to the index of the running task. os_task_global_index() = my_index; // Call the task function because of a timer timeout. my_func(); } return (task_does_have_event || task_does_have_timeout); }
/**************************************** Function name : paw_bisection Description : Return type : double Argument : *my_func)(double) Argument : double x1 Argument : double x2 Argument : double eps Author : Marat Valiev Date & Time : 9/30/98 ****************************************/ double paw_bisection(double (*my_func)(double), double x1, double x2, double eps) { int j; int root_found; double dx,f,fmid,xmid,root; root_found = False; fmid = my_func(x2); f = my_func(x1); if (f*fmid >=0.0) { printf(" paw_bisection.c : root must be bracketed"); exit(99); } if (f < 0.0) { root = x1; dx = x2-x1; } else { root = x2; dx = x1 - x2; } for (j=0;j<MAXIT;++j) { dx = 0.5*dx; xmid = root + dx; fmid = my_func(xmid); if (fmid <= 0.0) root = xmid; if (fabs(dx) < eps || fmid == 0.0 ) { root_found = True; break; } } if ( !(root_found)) { printf("unable to find root within alotted number of iterations"); exit(1); } return root; }
int amoeba_compare_vertices( const void* ap, const void* bp ) { double a, b ; a = my_func( *((double**) ap) ) ; b = my_func( *((double**) bp) ) ; if ( a > b ) { return -1 ; } else if ( a < b ) { return 1 ; } else { return 0 ; } }
void oop(){ int some_local_state = 0; func my_func(some_local_state); std::thread t(my_func); thread_guard g(t); std::cout << some_local_state << std::endl; }
void amoeba_go( AMOEBA* A ) { int step ; step = 1 ; while( ! amoeba_satisfied(A) && step < A->max_steps ) { step++ ; amoeba_order( A ) ; if ( amoeba_reflect( A ) ) { continue ; } if ( amoeba_expand( A ) ) { continue ; } if ( amoeba_contract( A ) ) { continue ; } amoeba_shrink( A ) ; } amoeba_order( A ) ; fprintf(stderr,"\n\nAmoeba search concluded.\n") ; fprintf(stderr,"Number iterations: %d \n", step) ; fprintf(stderr,"x=("); amoeba_print_point( A->num_dims, A->vertices[0] ) ; fprintf(stderr,")\n"); fprintf(stderr,"F(x)=%.6lf\n\n", my_func(A->vertices[0])); }
void oops() { int some_local_state=0; func my_func(some_local_state); std::thread my_thread(my_func); my_thread.detach(); }
int main() { struct ret_arr array; int ii; for ( ii = 0; ii < 5; ii++ ) { array.arr[ii] = 0; } array = my_func(); printf("&array = 0x%08x\n", &array); printf("&(array.arr) = 0x%08x\n", &(array.arr)); printf("&(array.arr[0]) = 0x%08x\n", &(array.arr[0])); printf("&(array.arr[1]) = 0x%08x\n", &(array.arr[1])); printf("&(array.arr[2]) = 0x%08x\n", &(array.arr[2])); printf("&(array.arr[3]) = 0x%08x\n", &(array.arr[3])); printf("&(array.arr[4]) = 0x%08x\n", &(array.arr[4])); for ( ii = 0; ii < 5; ++ii ) { printf("arr[%d] = %d; ", ii, array.arr[ii]); } printf("\n"); return 0; }
int main() { char m, y, z, w; int b = 2 * 3 - 10 ; int x = y + (z*w) / 2+2*m-2; int b = (x+m)*(z*w)*64; if( 10 + 15 < 12 * 2 -10 /2 ) { int a = 10; if( a < 890 ){ int c = 56789; } else { int j = 12412; } } else{ int my_val = 1234234 ; } while(a < 10){ int d = 100; if(a < 100){ int b = 11247098; } else {int a = 10000;} } my_func(b); }
int main(int argc, char *argv[]) { long local_var = 1; long local_var2 = 2; printf("Local function arguments:\n"); printf("\t&argc = 0x%lx\n", (long) &argc); printf("\t&argv = 0x%lx\n", (long) &argv); printf("\n"); printf("Local variables (main):\n"); printf("\t&local_var2 = 0x%lx\n", (long) &local_var2); printf("\t&local_var = 0x%lx\n", (long) &local_var); printf("\n"); my_func(local_var); printf("Static Data (global variables):\n"); printf("\t&variable = 0x%012lx\n", (long) &variable); printf("\t&array = 0x%012lx\n", (long) &array); printf("\n"); printf("Static Data (global constants):\n"); printf("\t&constant = 0x%012lx\n", (long) &constant); printf("\t&course = 0x%012lx\n", (long) &course); printf("\n"); printf("Code:\n"); printf("\t&my_func = 0x%012lx\n", (long) &my_func); printf("\t&main = 0x%012lx\n", (long) &main); printf("\n"); return 0; }
int my_func(struct node* node) { if (node == NULL) return 1; if (node-> left != NULL && node->left->data > node->data) return 0; if (node->right != NULL && node->right->data <= node->data) return 0; if(!my_func(node->left) || !my_func(node->right)) return 0; return 1; }
int main() { int some_local_state = 0; func my_func(some_local_state); std::thread t(my_func); thread_guard g(t); }
void f() { int some_local_state = 0; func my_func(some_local_state); std::thread t(my_func); thread_guard g(t);//方法二:确保当前线程退出时,正确等待线程t完成 do_something_in_current_thread(); }
void f() { int some_local_state; func my_func(some_local_state); std::thread t(my_func); thread_guard g(t); do_something_in_current_thread(); }
void f() { int local = 0; func my_func(local); std::thread t(my_func); try{ dosomethingincurrentthread(); }catch(...){ t.join(); throw; } t.join(); }
void init_ex10(py::module &m) { // Vectorize all arguments of a function (though non-vector arguments are also allowed) m.def("vectorized_func", py::vectorize(my_func)); // Vectorize a lambda function with a capture object (e.g. to exclude some arguments from the vectorization) m.def("vectorized_func2", [](py::array_dtype<int> x, py::array_dtype<float> y, float z) { return py::vectorize([z](int x, float y) { return my_func(x, y, z); })(x, y); } ); // Vectorize a complex-valued function m.def("vectorized_func3", py::vectorize(my_func3)); }
void dot_product (long N, double A[N], double B[N], double *acc){ double prod; *acc=0.0; int i; for (i=0; i<N; i++) { tareador_start_task("dot_product"); prod = my_func(A[i], B[i]); tareador_disable_object(acc); *acc += prod; tareador_enable_object(acc); tareador_end_task(); } }
int main(int argc, char** argv) { char buf[BUFFER_SIZE]; printf("Enter string: "); fflush(stdout); fgets(buf, BUFFER_SIZE, stdin); printf("Got string: %s\n", buf); my_func(buf); return 0; }
/* Main function */ int main() { int my_func(char*, char*); char *girdi1, *girdi2; char *p_girdi1; char *p_girdi2; int donen1; /* Allocating memory for input entries */ girdi1=malloc(sizeof(char)*200); p_girdi1=girdi1; girdi2=malloc(sizeof(char)*200); p_girdi2=girdi2; /* Reading the input */ scanf("%s", girdi1); /* Dividing the input string into two */ while(*p_girdi1) { if(*p_girdi1=='#') { p_girdi1++; my_strcopy(p_girdi2, p_girdi1); p_girdi1--; *p_girdi1='\0'; } p_girdi1++; } /* Pointers for two strings */ p_girdi1=girdi1; p_girdi2=girdi2; /*Return value of algorithm */ donen1=my_func(p_girdi1,p_girdi2); /*Printing the result */ if(donen1==2 || donen1==1) printf("T\n"); else if(donen1==3 || donen1==0) printf("F\n"); else; /* printf("%s\n", p_girdi1); printf("%s\n", p_girdi2); */ return 0; }
void f() { int some_local_state=0; func my_func(some_local_state); std::thread t(my_func); try { do_something(1); } catch(...) { t.join(); } t.join(); std::cout << "Done.\n"; }
void f() { int some_local_state=0; func my_func(some_local_state); std::thread t(my_func); try { do_something_in_current_thread(); } catch(...) { t.join(); throw; } t.join(); }
int amoeba_expand( AMOEBA* A ) { int ii ; double* x_0 ; double* x_r ; double* x_n ; double* x_e ; /* Short hand */ x_0 = A->vertices[0] ; x_r = A->x_refl ; x_n = A->vertices[A->num_vertices-1] ; x_e = A->x_expa ; if ( A->debug ) { fprintf(stderr,">> Try expansion.\n"); } /* Expand if F(x_r) > F(x_0) */ if ( my_func(x_r) <= my_func(x_0) ) { if ( A->debug ) { fprintf(stderr,">> Reject expansion.\n"); } return 0 ; } if ( A->debug ) { fprintf(stderr,">> Accept expansion.\n"); } if ( my_func(x_e) >= my_func(x_r) ) { /* Accept expansion point */ if ( A->debug ) { fprintf(stderr,"Accept x_e("); amoeba_print_point( A->num_dims, x_e ) ; fprintf(stderr,") F(x_e)=%.2lf \n", my_func(x_e) ) ; } for ( ii = 0 ; ii < A->num_dims+1 ; ii++ ) { x_n[ii] = x_e[ii] ; } } else { /* Accept reflection point */ if ( A->debug ) { fprintf(stderr,"Accept x_r("); amoeba_print_point( A->num_dims, x_r ) ; fprintf(stderr,") F(x_r)=%.2lf \n", my_func(x_r) ) ; } for ( ii = 0 ; ii < A->num_dims+1 ; ii++ ) { x_n[ii] = x_r[ii] ; } } return 1 ; }
void f() { int some_local_state=0; func my_func(some_local_state); std::thead t(my_func); try { do_some_in_current_thread(); } catch(...) { t.join(); throw; }//方法一: 使用try --catch 确保在意外退出时仍然正确调用t.join等待函数 t.join(); }
struct func { int& i; func(int& i_):i(i_) {} void operator()() { for(unsigned j=0; j<1000; ++j) { // do something; } } } void f() { int some_local_state = 0; func my_func(some_local_state); std::thread t(my_func); try { // do something in current thread } catch(...) { t.join(); throw; } t.join(); }
int amoeba_reflect( AMOEBA* A ) { int ii ; double* x_0 ; double* x_r ; double* x_n ; if ( A->debug ) { fprintf(stderr,">> Try reflection.\n"); } /* Short hand */ x_0 = A->vertices[0] ; x_r = A->x_refl ; x_n = A->vertices[A->num_vertices-1] ; if ( my_func(x_0) >= my_func(x_r) && my_func(x_r) > my_func(x_n) ) { /* Accept reflection point --- replace worst point with x_r */ if ( A->debug ) { fprintf(stderr,"Accept reflection x_r("); amoeba_print_point( A->num_dims, x_r ) ; fprintf(stderr,") F(x_r)=%.2lf \n", my_func(x_r) ) ; } for ( ii = 0 ; ii < A->num_dims+1 ; ii++ ) { x_n[ii] = x_r[ii] ; } return 1 ; } else { if ( A->debug ) { fprintf(stderr,"Reject reflection x_r("); amoeba_print_point( A->num_dims, x_r ) ; fprintf(stderr,") F(x_r)=%.2lf \n", my_func(x_r) ) ; } return 0 ; } }
/* Function for R4 */ int transformation4(char* trp_girdi1,char* trp_girdi2) { int my_func(char* girdi1, char* girdi2); char *bir_bas; char *p_bir; char *ilk_virgul; char *ikinci_virgul; char *kontrol; char *virgul; char *bolunen1; char *bolunen2; char *bolunen12; char *bolunen11; virgul=","; bir_bas=trp_girdi2; p_bir=bir_bas; bolunen1=calloc(200,sizeof(char)); bolunen2=calloc(200,sizeof(char)); bolunen11=calloc(200,sizeof(char)); bolunen12=calloc(200,sizeof(char)); my_strcopy(bolunen11,trp_girdi1); my_strcopy(bolunen12,trp_girdi1); while(*p_bir) { if(*p_bir=='&') { /* Locate the previous comma */ for(kontrol=p_bir;kontrol>=bir_bas;kontrol--) if(*kontrol==',' || kontrol==bir_bas ) { ilk_virgul=kontrol; break; } /*Locate the next comma */ for(kontrol=p_bir;;kontrol++) if(*kontrol==',' || *kontrol=='\0' ) { ikinci_virgul=kontrol; break; } /* Create the divided part I */ strncat(bolunen1, bir_bas,(ilk_virgul-bir_bas)); strcat(bolunen1, virgul); strncat(bolunen1,ilk_virgul+2,(p_bir-ilk_virgul-2)); strcat(bolunen1,ikinci_virgul); /* Create the divided part II */ strncat(bolunen2, bir_bas,(ilk_virgul-bir_bas)); strcat(bolunen2, virgul); strncat(bolunen2,p_bir+1,(ikinci_virgul-p_bir-2)); strcat(bolunen2,ikinci_virgul); /* Control for the divided parts */ /* printf("bolunen1: %s\n", bolunen1); printf("bolunen2: %s\n", bolunen2); */ if( (my_func(bolunen11,bolunen1) == 2 || my_func(bolunen11,bolunen1) == 1 ) && (my_func(bolunen12,bolunen2) == 2 || my_func(bolunen12,bolunen2) == 1) ) { return 1; } else { return 0; } break; } p_bir++; } return 0;}
int main() { int a,b,c;char xo;double ox; char cxxx[10][20];double dxxx[20][34]; dxxx[12][13]=cxxx[3][4]*cxxx[3][4]; a=b*ox*xo; a=xo; xo=a; a=ox; ox=a; xo=ox; ox=xo; c=-5; b=4; a=3; c=3*b+(a-b); c=a; int x; x=1; int y;char c1; y=my_func(a,b,c1); if((a!=b)&&(b==c)) a=b+c; else{ x=x*x; } a=3<4?5:2; double d1,d2; d1=10.123;d2=2.23; char d='a'; d='b'; int a1[100][200],x1=23,y5=-25,x3=10; array_fn(a1,y5,x3); a1[20][30]=2; int xx; xx=a1[20][30]+x1; c=a=2; int xxxx,***pp,aaaa[10][121][21]; char ***pc,ac[32][23][1][2],xc,**ppc; myfunc2(a,b); int xxxx,***pp,aaaa[10][12][21]; char ***pc; int aabb[23][1][2],xc,**ppc; c=a+++++a+b+++--b+++c; return 1; }
int main (void) { printf ("my_func (4, 12) yields: %d\n", my_func (4, 12)); return 0; }
double run(int threads_num, double b) { int i, j, step,k; double* y = calloc(N + 1, sizeof(double)); /* сеточное решение */ double* dy = calloc(N + 1, sizeof(double)); /* разность y^n-y^n+1 двух соседних приближений по итерациям метода Ньютона */ double *A[R], *B[R], *C[R], *G[R]; /* коэффициенты трёхдиагональной системы для каждого шага редукции */ double begin, end; omp_set_dynamic(0); /* нельзя динамически изменять количество нитей */ omp_set_num_threads(threads_num); /* 4 нити */ for(i = 0; i < R; i++) { A[i] = calloc(N + 1, sizeof(double)); B[i] = calloc(N + 1, sizeof(double)); C[i] = calloc(N + 1, sizeof(double)); G[i] = calloc(N + 1, sizeof(double)); } begin = omp_get_wtime(); /* начальная точка отсчёта времени */ for( k = 0; k < REPEATS; k++){ #pragma omp parallel private(i, j) { #pragma omp for for(i = 0; i <= N; i++) y[i] = 1.0 + (b - 1.0) * i / N; /* нулевое приближение */ #pragma omp single { dy[0] = dy[N] = 0.0; for(j = 0; j < R; j++) B[j][0] = B[j][N] = 1.0; /* при редукции крайние значения матрицы одни и те же во всех итерациях метода Ньютона */ } while(1) /* итерации метода Ньютона в цикле */ { #pragma omp for for(i = 1; i < N; i++) /* изначальные значения коэффициентов */ { B[0][i] = (-2.0 / (h * h) - 5 * exp(y[i]) / 6); A[0][i] = (1.0 / (h * h) - exp(y[i - 1]) / 12); C[0][i] = (1.0 / (h * h) - exp(y[i + 1]) / 12); G[0][i] = my_func(y, b, i); } for(j = 1; j < R; j++) /* значения коэффициентов после редукции */ { step = pow(2, j); /* шаг прогонки при редукции */ #pragma omp for for(i = step; i < N; i += step) { B[j][i] = B[j - 1][i] - A[j - 1][i] * C[j - 1][i - step / 2] / B[j - 1][i - step / 2] - C[j - 1][i] * A[j - 1][i + step / 2] / B[j - 1][i + step / 2]; A[j][i] = - A[j - 1][i] * A[j - 1][i - step / 2] / B[j - 1][i - step / 2]; C[j][i] = - C[j - 1][i] * C[j - 1][i + step / 2] / B[j - 1][i + step / 2]; G[j][i] = G[j - 1][i] - A[j - 1][i] * G[j - 1][i - step / 2] / B[j - 1][i - step / 2] - C[j - 1][i] * G[j - 1][i + step / 2] / B[j - 1][i + step / 2]; } } /* редукция прогонки завершена */ #pragma omp single { dy[N / 2] = G[R - 1][N / 2] / B[R - 1][N / 2]; /* первый обратный шаг редукции */ dy[N / 4] = (G[R - 2][N / 4] - C[R - 2][N / 4] * dy[N / 2]) / B[R - 2][N / 4]; dy[N * 3 / 4] = (G[R - 2][N * 3 / 4] - A[R - 2][N * 3 / 4] * dy[N / 2] ) / B[R - 2][N * 3 / 4]; /* второй обратный шаг редукции */ } for(j = R - 3; j >= 0; j--) { step = pow(2, j); #pragma omp for for(i = step; i < N; i += 2 * step) dy[i] = (G[j][i] - C[j][i] * dy[i + step] - A[j][i] * dy[i - step]) / B[j][i]; } /* оставшиеся обратные шаги редукции */ #pragma omp for for(i = 0; i <= N; i++) y[i] -= dy[i]; /* одна итерация метода Ньютона */ if (norm(dy) < epsilon) break; /* условие останова метода Ньютона */ } } } end = omp_get_wtime(); /* конечная точка отсчёта времени */ for(i = 0; i < R; i++) { free(A[i]); free(B[i]); free(C[i]); free(G[i]); } if( threads_num == 1){ char str_dest[50]; sprintf( str_dest, "prog_1_b_%f_results.txt",b); FILE* fp = fopen(str_dest, "w"); /* вывод полученной функции в файл */ fprintf(fp, "X\tY\r\n"); for(i = 0; i <= N; i++) fprintf(fp, "%e\t%e\r\n", ((double) i / N), y[i]); fclose(fp); } free(y); free(dy); return (end - begin)/REPEATS; }
int amoeba_contract( AMOEBA* A ) { int ii ; double* x_r ; double* x_n ; double* x_n_1 ; double* x_c ; double* x_cont ; /* Short hand */ x_c = A->x_cent ; x_r = A->x_refl ; x_n = A->vertices[A->num_vertices-1] ; x_n_1 = A->vertices[A->num_vertices-2] ; x_cont = A->x_cont ; if ( A->debug ) { fprintf(stderr,">> Try contraction.\n"); } /* Contract if F(x_r) < F(x_n-1) */ if ( my_func(x_r) >= my_func(x_n_1) ) { if ( A->debug ) { fprintf(stderr,">> Reject contraction.\n"); } return 0 ; } /* Calculate contraction point * x_contract = x_center + zeta*(x_center - x_worst) */ for ( ii = 0 ; ii < A->num_dims ; ii++ ) { x_cont[ii] = x_c[ii] + AMOEBA_ZETA*(x_c[ii] - x_n[ii]) ; } if ( my_func(x_cont) >= my_func(x_n) ) { /* Accept contraction point */ if ( A->debug ) { fprintf(stderr,">> Accept contraction about x_cont("); amoeba_print_point( A->num_dims, x_cont ) ; fprintf(stderr,") F(x_cont)=%.2lf \n", my_func(x_cont) ) ; } for ( ii = 0 ; ii < A->num_dims+1 ; ii++ ) { x_n[ii] = x_cont[ii] ; } return 1 ; } else { /* Reject contraction point */ if ( A->debug ) { fprintf(stderr,">> Reject contraction about x_cont("); amoeba_print_point( A->num_dims, x_cont ) ; fprintf(stderr,") F(x_cont)=%.2lf \n", my_func(x_cont) ) ; } return 0 ; } }
void main() { my_func(); return; }