int create_eye(t_all *all, t_list *list, FILE *fd, int *err) { char *str; int i; list = NULL; i = 0; while ((str = get_next_line_custom(fd)) != NULL && ++ i > 0 && lexer(&list, str) != -1 && the_end(list, "EYE") == -1) { if ((strcmp("pos", (list = list->next)->lexeme) == 0 && init_coords(list->next, &all->eye.pos) == -1) || (strcmp("rot", list->lexeme) == 0 && init_coords(list->next, &all->eye.rot) == -1) || (strcmp("rot", list->lexeme) != 0 && strcmp("pos", list->lexeme) != 0)) *err = -1; free_things(list, str); if (*err == -1) return (-1); list = NULL; } if (the_end(list, "EYE") == 0) return (i); *err = -1; return (i); }
static void * init_drive(lemuria_engine_t * e) { drive_data * d; int random_number; d = calloc(1, sizeof(*d)); init_coords(d); d->delta_phi_start = 0.0; d->delta_phi_end = 0.0; lemuria_range_init(e, &(d->curvature_range), 1, 10, 10); random_number = lemuria_random_int(e, 0, 1); // random_number = 1; switch(random_number) { case 0: lemuria_background_init(e, &(d->drive_background), &(bg_drive_1)); break; case 1: lemuria_background_init(e, &(d->drive_background), &(bg_drive_2)); break; } if(e->goom) random_number = lemuria_random_int(e, 0, 1); else random_number = 1; // random_number = 1; switch(random_number) { case 0: lemuria_background_init(e, &(d->sky_background), &(sky_goom)); break; case 1: lemuria_background_init(e, &(d->sky_background), &(sky_lemuria)); break; } d->speed_start = 0.0; d->speed_end = SPEED_MIN + (e->loudness / 32768.0)*(SPEED_MAX - SPEED_MIN); lemuria_range_init(e, &(d->speed_range), 1, 50, 60); return d; }
void change_set(infoptr pic, point julia_pos) /* julia_pos=hiiren klikkauspiste */ { if(pic->is_mandel) /* Mandelbrot -> Julia */ { pic->is_mandel = FALSE; pic->julia_c = to_dpoint(julia_pos, pic); init_coords(pic); repaint(pic, pic->area); } else /* Julia -> Mandelbrot */ { pic->is_mandel = TRUE; init_coords(pic); repaint(pic, pic->area); } }
void paint_julia_prev(infoptr pic, point mouse_pos) { struct picture_info prev_pic; dpoint p, tmp; int n = 0; prev_pic.area = get_prev_rect(pic); init_coords(&prev_pic); /* Asetetaan sopiva skaalaus */ /* Julia-vakio hiiren koordinaateista */ prev_pic.julia_c = to_dpoint(mouse_pos, pic); SRGP_setClipRectangle(prev_pic.area); SRGP_setColor(SRGP_BLACK); /* Peitetään vanha kuva */ SRGP_fillRectangleCoord(prev_pic.area.bottom_left.x + 1, prev_pic.area.bottom_left.y + 1, prev_pic.area.top_right.x - 1, prev_pic.area.top_right.y - 1); SRGP_setColor(SRGP_WHITE); /* Valkea reunus */ SRGP_rectangle(prev_pic.area); p.x = 0; /* Inverse functionin */ p.y = 0; /* alkupiste */ while(n < JULIA_LIMIT) { /* z[n+1] = sqrt(z[n] - c) */ tmp.x = p.x - prev_pic.julia_c.x; tmp.y = p.y - prev_pic.julia_c.y; p = c_sqrt(tmp); SRGP_point(to_point(p, &prev_pic)); n++; } SRGP_setClipRectangle(pic->area); }
// initialize player's match information (coords) void init_player_match(Player_Match* process) { int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); process->global_rank = rank; // field does not have coordinates if (rank == FIELD_0 || rank == FIELD_1) { process->initial_coords[0] = INVALID_COORDS ; process->initial_coords[1] = INVALID_COORDS ; process->final_coords[0] = INVALID_COORDS ; process->final_coords[1] = INVALID_COORDS ; process->ball_coords[0] = LONG_SIDE/2 ; process->ball_coords[1] = SHORT_SIDE/2 ; process->reached = INVALID ; process->challenge = INVALID ; } else { // initial coordinates of players are random init_coords(process->initial_coords) ; process->final_coords[0] = INVALID_COORDS ; process->final_coords[1] = INVALID_COORDS ; process->ball_coords[0] = INVALID_COORDS ; process->ball_coords[1] = INVALID_COORDS ; process->reached = 0 ; process->challenge = 0 ; } }
coords* read_newcoo(char *filename) { FILE *FP; vec boxL = {.x=-1.0, .y=-1.0, .z=-1.0}; char *buffer = (char*)calloc(MAX_LEN, sizeof(char)); char *fileformat = (char*)calloc(7, sizeof(char)); int i=0, nat=0; printf("\nread_newcoo: filename = %s",filename); FP=fopen(filename, "rt"); if (FP == NULL) { printf("\n*** read_newcoo:Could not open <%s>.", filename); return NULL; } // read first line of file to get nat, boxL and confirm newcoo-format if (fgets(buffer, MAX_LEN, FP) == NULL) { printf("\n*** read_newcoo: read from input file failed"); return NULL; } sscanf(buffer,"%7s %6d %lf %lf %lf",fileformat, &nat, &boxL.x, &boxL.y, &boxL.z); trim(fileformat); if (strncmp(fileformat, "new-coo", 7) != 0) { printf("\n*** read_newcoo: file format to read is incompatible (not new-coo)"); return NULL; } coords *coo = init_coords(nat, boxL); printf("\n*** read_newcoo: header = %7s %6d %10.6f %10.4f %10.4f",fileformat, nat, boxL.x, boxL.y, boxL.z); for(i=0;i<coo->nat;i++) { fgets(buffer, MAX_LEN, FP); sscanf(buffer, "%5d %2s %2d %lf %lf %lf\n", &(coo->at[i]->n), coo->at[i]->esymb, &(coo->at[i]->atn), &(coo->at[i]->pnt.x), &(coo->at[i]->pnt.y), &(coo->at[i]->pnt.z)); } fclose(FP); return coo; }
int main(int argc, char *argv[]) { int dev, ret_val; unsigned int reg_val; // find and init FPGA device ret_val = fpga_init(argc, argv, &dev); if (ret_val<0) return -1; double dt_c[N]; double dt_f[N]; printf("N_d is %d\n",N_d); printf("N_d is %d\n",N_d); printf("size is %d\n",(int)SIZE_DWORD); try{ x_1.resize(13); y_1.resize(13); t_1.resize(13); x_2.resize(13); y_2.resize(13); t_2.resize(13); for (int i = 0; i < 13; i++){ x_1[i].resize(N_d); y_1[i].resize(N_d); t_1[i].resize(N_d); x_2[i].resize(N_d); y_2[i].resize(N_d); t_2[i].resize(N_d); } } catch (const std::bad_alloc& ba){ std::cout << "bad_alloc caught: " << ba.what() << std::endl; } FILE *f_p, *f_p1; int error = 0; if (flag_compare==1){ f_p = fopen ("MT_coords_CPU.txt","w"); if (f_p==NULL) { printf("Error opening file!\n"); return -1; } } if (flag_file) f_p1 = fopen (out_file,"w"); else f_p1 = fopen ("MT_coords_FPGA.txt","w"); if (f_p1==NULL) { printf("Error opening file!\n"); return -1; } printf("TOTAL_STEPS = %d\nSTEPS_TO_WRITE = %d\n", TOTAL_STEPS, STEPS_TO_WRITE); // get golden results init_coords(x_1,y_1,t_1); init_coords(x_2,y_2,t_2); /* * в этом цикле проводим вычислени¤ и сравниваем результаты * * в данный момент чтобы проверить сравнение на каждом шаге вызываетс¤ функци¤ mt_cpu * с параметром load_coords = 1 (иначе состо¤ни¤ глобальных массивов координат будет все врем¤ мен¤тьс¤) * * огда вместо mt_cpu будет реализаци¤ на OpenCL, то надо делать по-другому: * перед циклом один раз вызываем mt_cpu (load_coords = 1), в цикле уменьшаем количество итераций на 1 и * вызываем mt_cpu (load_coords = 0) * */ error = 0; printf("\nFlag rand is SET, %d\n\n",flag_rand); if (flag_rand==1) { srand (time(NULL)); // set seed vals for (int i =0; i < NUM_SEEDS; i++){ #ifdef TEST_SEEDS seeds[i] = test_seeds[i]; #else seeds[i]=rand(); #endif unsigned int addr = SEED_REG + 4*i; RD_WriteDeviceReg32m(dev, CNTRL_BAR, addr, seeds[i]); } printf("\nFlag rand is SET\n\n"); RD_ReadDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); // deassert rand reset reg_val |= (1<<4); RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); // set rand_enable flag reg_val |= (1<<7); RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); // start rand core reg_val |= (1<<5); RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); } printf("\n\nhereerereerere\n\n"); for(int k=0; k<N; k++) { int err; struct timeval tt1, tt2; if (flag_compare==1){ get_time(&tt1); if (mt_cpu(STEPS_TO_WRITE,1, flag_rand, flag_seed, seeds, x_1,y_1,t_1,x_1,y_1, t_1)<0) { printf("Nan Error in cpu. Step is %d. Exitting....\n",k); break;} get_time(&tt2); calc_dt(&tt1,&tt2, &dt_c[k]); } get_time(&tt1); mt_fpga(dev,STEPS_TO_WRITE,1,x_2,y_2,t_2,x_2,y_2, t_2); get_time(&tt2); calc_dt(&tt1,&tt2, &dt_f[k]); flag_seed = 0; printf("Step %d\n\t CPU Time = %f\n\t FPGA Time = %f\n",k,dt_c[k],dt_f[k] ); if (flag_compare==1){ err = compare_results(x_1,y_1,t_1,x_2,y_2,t_2); if (err) { error += err; printf("Compare results failed at step = %d, errors = %d\n", k, error); } } if (flag_compare==1) print_coords(f_p, x_1, y_1, t_1); print_coords(f_p1, x_2, y_2, t_2); } if (flag_compare==1){ if (!error) printf("Test OK!\n"); } if (flag_compare==1) fclose(f_p); fclose(f_p1); RD_ReadDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); // assert rand reset reg_val &= ~(1<<4); RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); // reset rand_enable flag reg_val &= ~(1<<7); RD_WriteDeviceReg32m(dev, CNTRL_BAR, COMMAND_REG, reg_val); free(wr_buf_free); free(rd_buf_free); RD_CloseDevice(pd_ptr); return 0; }