inline static void calc_new_pts_normal(double (*calc_x)(), double (*calc_y)(), double (*calc_z)(), t_vec3 **arg) { t_vec3 *d; t_vec3 *ori; t_vec3 tmp; t_intersect inter; d = arg[0]; ori = arg[1]; update_inter_normal(&inter, ori, 0.000000001, 0.000000001); inter.pos.z = -(d[0].x * (inter.pos.x - ori->x) + d[0].y * (inter.pos.y - ori->y)) / d[0].z + ori->z; calc_tmp_normal(&tmp, &inter); d[1].x = calc_x(&inter, tmp); d[1].y = calc_y(&inter, tmp); d[1].z = calc_z(&inter, tmp); update_inter_normal(&inter, ori, -0.000000001, -0.000000002); inter.pos.z = -(d[0].x * (inter.pos.x - ori->x) + d[0].y * (inter.pos.y - ori->y)) / d[0].z + ori->z; calc_tmp_normal(&tmp, &inter); d[2].x = calc_x(&inter, tmp); d[2].y = calc_y(&inter, tmp); d[2].z = calc_z(&inter, tmp); }
si3::Coor3 Triangler::get_random() const { si3::Coor3 coor; coor.z = 0.0f; int type = fw::xrandom() % 4; if (type==0) { coor.x = 11.0f; coor.y = calc_y(); } else if (type == 1) { coor.x = -11.0f; coor.y = calc_y(); } else if (type == 2) { coor.x = calc_x(); coor.y = 7.0f; } else if (type == 3) { coor.x = calc_x(); coor.y = -7.0f; } return coor; }
void main() { foo(); printf("O dobro de 2 eh:%d\n",calc_x(2)); printf("numrodas:%d\n",NUM_RODAS); }
void calc_normale(double (*calc_x)(), double (*calc_y)(), double (*calc_z)(), t_intersect *inter) { t_vec3 d[3]; t_vec3 v[2]; t_vec3 tmp; calc_tmp_normal(&tmp, inter); d[0].x = calc_x(inter, tmp); d[0].y = calc_y(inter, tmp); d[0].z = calc_z(inter, tmp); calc_new_pts_normal(calc_x, calc_y, calc_z, (t_vec3*[2]){d, &inter->pos});
int main (int argc, char **argv) { #if defined(_DIST_) CnC::dist_cnc_init< HeatEquation_bl_context > AAA; #endif // CnC::debug::set_num_threads(1); tbb::tick_count t0 = tbb::tick_count::now(); if( argc < 3 ) { std::cerr << "expecting 2 arguments: <file> <blocksize>\n"; exit( 1 ); } global_data d; int& block_size = d.block_size; int& Nx = d.Nx; int& Nt = d.Nt; int& N_bl = d.N_bl; double& Xa = d.Xa; double& Xb = d.Xb; double& T0 = d.T0; double& T1 = d.T1; double& k = d.k; double& hx = d.hx; double& ht = d.ht; block_size = atoi(argv[2]); if(block_size < 1) { std::cerr<<"Bad block size\n"; return 0; } { std::ifstream from(argv[1]); if( ! from ) { std::cerr << "couldn't open " << argv[1] << std::endl; exit( 2 ); } from >> d.Xa >> d.Xb >> d.Nx >> d.T0 >> d.T1 >> d.Nt >> d.k; from.close(); } if( block_size > Nx+1 ) { block_size = Nx+1; } else { Nx = ((Nx+1+block_size-1)/block_size)*block_size-1; } HeatEquation_bl_context c; hx = ( Xb - Xa ) / Nx; ht = ( T1 - T0 ) / Nt; // for ( int i = 0; i < Nx + 1; i++ ) { c.X.put(i,Xa+i*hx); } // for ( int i = 0; i < Nt + 1; i++ ) { c.T.put(i,T0+i*ht); } N_bl = (Nx+1) / block_size; c.gd.put(0,d); for ( int i = 0; i < N_bl; i++ ) { my_array<double> z(block_size); for(int j = 0; j < block_size; j++ ){ double x = calc_x(block_size*i+j,Xa,Xb,Nx); z.data[j] = Analitical( x, T0 ); } c.H.put(Pair(0,i),z); } Pair p; p.It = 1; for ( int j = 0; j < N_bl; j++ ) { p.Jx = j; c.Tag.put( p ); } // Wait for all steps to finish c.wait(); tbb::tick_count t1 = tbb::tick_count::now(); std::cout<<"Time taken: "<< (t1-t0).seconds()<<" \n"; if (argc >= 4){ for (int i = 0; i <= Nt; i++) { for (int j = 0; j < N_bl; j++){ my_array<double> z; c.H.get(Pair(i,j),z); for (int k = j*block_size; k < j*block_size+block_size && k <= Nx; k++){ printf("%.6lf ",double(z.data[k-j*block_size])); } } puts(""); } } Eo(N_bl); Eo(Nt); return 0; }
int Step::execute( const Pair & tag, HeatEquation_bl_context & c ) const { global_data d; c.gd.get(0,d); double k = d.k; double hx = d.hx; double ht = d.ht; int block_size = d.block_size; int N_bl = d.N_bl; double Xa = d.Xa; double Xb = d.Xb; double T0 = d.T0; double T1 = d.T1; int Nx = d.Nx; int Nt = d.Nt; int i,j; // printf("%d %d %d\n",tag.It,tag.Jx,z); my_array<double> h[3]; i = tag.It; j = tag.Jx; // printf("@%03d:%03d",i,j); if(j) c.H.get( Pair( i-1, j-1 ),h[0]); c.H.get(Pair( i-1, j ),h[1]); if( j+1 < N_bl ) c.H.get(Pair( i-1, j+1 ),h[2]); double a[3]; my_array<double> outdata(block_size); double t = T0+((T1-T0)/double(Nt+1))*i; int m_start = 0; int m_end = block_size; if (!j){ outdata.data[0] = Analitical(Xa,t); m_start = 1; } if (j == (N_bl-1)) { m_end = block_size-1; outdata.data[block_size-1] = Analitical(Xb,t); } for(int m = m_start; m < m_end; m++) { if (block_size == 1){ a[0] = h[0].data[block_size-1]; a[1] = h[1].data[0]; a[2] = h[2].data[0]; } else { if(!m) { a[0] = h[0].data[block_size-1]; a[1] = h[1].data[0]; a[2] = h[1].data[1]; } else if(m == block_size-1) { a[0] = h[1].data[block_size-2]; a[1] = h[1].data[block_size-1]; a[2] = h[2].data[0]; } else { for(int n = 0; n < 3; n++){ a[n] = h[1].data[n+m-1]; } } } double x = calc_x(m+block_size*j,Xa,Xb,Nx); outdata.data[m] = Update( x, t, k, hx, ht, &a[0] ); } c.H.put(tag, outdata); if (i+1 <= Nt){ Pair next_tag; next_tag.It = i+1; next_tag.Jx = j; c.Tag.put(next_tag); } //printf("!%03d:%03d",i,j), fflush(stdout); return CnC::CNC_Success; }