void test_nested_eval() { /* Inner list: (+ 1 2) */ Cell * inner_list = get_one_plus_two(); Cell * outer_list = alloc_cell(); Cell * three = alloc_int_cell(3); Cell * four = alloc_int_cell(4); Cell * result = eval(inner_list); g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, 3); /* Outer list: (+ 3 (+ 1 2) 4) = 10 */ Cell * branch = alloc_cell(); set_car_ptr(outer_list, ADD_OP_CELL, NULL); set_cdr_ptr(outer_list, LIST_CELL, three); set_cdr_ptr(three, LIST_CELL, branch); set_car_ptr(branch, LIST_CELL, inner_list); set_cdr_ptr(branch, LIST_CELL, four); result = eval(outer_list); g_assert_cmpint(result->car.data.int_value, ==, 10); }
void unpack_cell( msgbuf *b, int j, int k ) { int i; int tmp_n; cell *to; to = PTR_2D_V(cell_array, j, k, cell_dim); tmp_n = (int) b->data[ b->n++ ]; if (tmp_n > to->n_max) { to->n = 0; alloc_cell(to, tmp_n); } to->n = tmp_n; for (i=0; i<to->n; ++i) { ORT(to,i,X) = b->data[ b->n++ ]; ORT(to,i,Y) = b->data[ b->n++ ]; #ifndef MONO SORTE(to,i) = (shortint) b->data[ b->n++ ]; #endif } if (b->n_max < b->n) error("Buffer overflow in unpack_cell"); }
/* insert_in_list_on_position inserts a new item on the indicated position of a list */ void insert_in_list_on_position(object_type item, list_pointer *p, list_type *list) { list_pointer aux=*p; if (aux==NULL) { *p=NULL; return; } /* Tests if the pointer is pointing to the dummy cell. * In this case we will just insert the item on the last of the list */ if (aux==list->first) { insert_in_list(item, list); } else { /* Tests if the pointer is pointing to the real first item of the list. * In this case we will insert the item on the first position of the list */ if(aux==list->first->next) insert_in_begin_list(item, list); else { aux->previous->next=alloc_cell(); aux->previous->next->previous=aux->previous; aux->previous=aux->previous->next; aux->previous->item=item; aux->previous->next=aux; list->length++; } } *p=aux->previous; }
void test_add_eval() { Cell * add_op = alloc_cell(); set_car_ptr(add_op, ADD_OP_CELL, NULL); Cell * result = eval(add_op); //test base case: (+) --> 0 g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, 0); Cell * one = alloc_int_cell(1); Cell * two = alloc_int_cell(2); set_cdr_ptr(add_op, LIST_CELL, one); set_cdr_ptr(one, LIST_CELL, two); result = eval(add_op); //(+ 1 2) --> 3 g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, 3); Cell * three = alloc_int_cell(3); set_cdr_ptr(two, LIST_CELL, three); result = eval(add_op); //(+ 1 2 3) --> 6 g_assert_cmpint(result->car.data.int_value, ==, 6); }
void create_empty_list(list_type *list) { list->first=alloc_cell(); list->last=list->first; list->first->next=list->first; list->first->previous=list->first; list->length=0; }
void read_stress(str255 infilename) { cell *to; FILE *infile; char buf[512]; int p,nr,typ; double mass; vektor pos, sigma, sigma_offdia; ivektor cellc; infile = fopen(infilename,"r"); if (NULL==infile) { sprintf(error_msg,"Cannot open atoms file %s",infilename); error(error_msg); } natoms=0; /* Read the input file line by line */ while(!feof(infile)) { buf[0] = (char) NULL; fgets(buf,sizeof(buf),infile); while ('#'==buf[1]) fgets(buf,sizeof(buf),infile); /* eat comments */ #ifdef TWOD p = sscanf(buf,"%lf %lf %lf %lf %lf", &pos.x,&pos.y,&sigma.x,&sigma.y,&sigma_offdia.x); #else p = sscanf(buf,"%d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &nr,&typ,&mass,&pos.x,&pos.y,&pos.z,&sigma.x,&sigma.y,&sigma.z, &sigma_offdia.x,&sigma_offdia.y,&sigma_offdia.z); #endif if (p>0) { /* compute target cell */ cellc = cell_coord(pos); to = PTR_VV(cell_array,cellc,cell_dim); /* enlarge it if necessary */ if (to->n >= to->n_max) alloc_cell(to,to->n_max+CSTEP); /* put the data */ to->nummer[to->n] = nr; to->sorte[to->n] = typ; to->masse[to->n] = mass; to->ort[to->n] = pos; to->stress[to->n] = sigma; to->stress_offdia[to->n] = sigma_offdia; to->n++; natoms++; } } fclose(infile); }
/* insert_in_list inserts a new item on the last position of a list */ void insert_in_list(object_type item, list_type *list) { list->last->next=alloc_cell(); list->last->next->previous=list->last; list->last=list->last->next; list->last->item=item; list->last->next=list->first; list->first->previous=list->last; list->length++; }
//// similar to b_cons(), which returns a pntr pointing to a cell pntr make_cons(task *tsk, pntr head, pntr tail) { pntr newCellPntr; cell *res = alloc_cell(tsk); res->type = CELL_CONS; res->field1 = head; res->field2 = tail; make_pntr(newCellPntr,res); return newCellPntr; }
void test_set_car_cdr() { Cell *cell1, *cell2; cell1 = alloc_cell(); cell2 = alloc_cell(); set_car_int(cell1, 1); set_cdr_int(cell1, 2); g_assert_cmpint(car_type(cell1), ==, INTEGER_CELL); g_assert_cmpint(cell1->car.data.int_value, ==, 1); g_assert_cmpint(cdr_type(cell1), ==, INTEGER_CELL); g_assert_cmpint(cell1->cdr.data.int_value, ==, 2); set_car_ptr(cell1, LIST_CELL, cell2); g_assert_cmpint(car_type(cell1), ==, LIST_CELL); g_assert(cell1->car.data.ptr_value == cell2); set_cdr_ptr(cell2, LIST_CELL, cell1); g_assert_cmpint(cdr_type(cell2), ==, LIST_CELL); g_assert(cell2->cdr.data.ptr_value == cell1); }
Cell * get_one_plus_two() { Cell * add_op = alloc_cell(); Cell * one = alloc_int_cell(1); Cell * two = alloc_int_cell(2); /* Inner list: (+ 1 2) */ set_car_ptr(add_op, ADD_OP_CELL, NULL); set_cdr_ptr(add_op, LIST_CELL, one); set_cdr_ptr(one, LIST_CELL, two); return add_op; }
struct s_Row *alloc_row(struct s_Row *prev_row) { struct s_Row *new_row = malloc(sizeof(struct s_Row)); new_row -> next_row = 0; new_row -> cell_count = 0; new_row -> first_cell = alloc_cell(new_row, 0); if (prev_row) prev_row->next_row = new_row; return new_row; }
/* Inserts a new item on the first position of a list */ void insert_in_begin_list(object_type item, list_type *list) { list_pointer aux; aux=alloc_cell(); aux->item=item; aux->next=list->first->next; aux->next->previous=aux; list->first->next=aux; aux->previous=list->first; if (list->length==0) list->last=aux; list->length++; }
void test_lambda_simple() { init_eval(); Cell *lambda = alloc_cell(); Cell *a = alloc_cell(); Cell *code = get_one_plus_two(); set_car_ptr(lambda, LAMBDA_CELL, NULL); set_cdr_ptr(lambda, LIST_CELL, a); set_car_ptr(a, SYMBOL_CELL, g_strdup("a")); set_cdr_ptr(a, LIST_CELL, code); eval(lambda); Cell *ptr = g_hash_table_lookup(symbol_table, g_strdup("a")); g_assert(code == ptr); Cell *a2 = alloc_cell(); set_car_ptr(a2, SYMBOL_CELL, g_strdup("a")); Cell *result = eval(a2); g_assert_cmpint(result->car.type, ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, 3); }
void read_displacement(str255 infilename) { FILE *infile; char buf[512]; int p; vektor pos; vektor u; cell *to; ivektor cellc; infile = fopen(infilename,"r"); if (NULL==infile) { sprintf(error_msg,"Cannot open atoms file %s",infilename); error(error_msg); } natoms=0; /* Read the input file line by line */ while (!feof(infile)) { buf[0] = (char) NULL; fgets(buf,sizeof(buf),infile); while ('#'==buf[1]) fgets(buf,sizeof(buf),infile); /* eat comments */ #ifdef TWOD p = sscanf(buf,"%lf %lf %lf %lf",&pos.x,&pos.y,&u.x,&u.y); #else p = sscanf(buf,"%lf %lf %lf %lf %lf %lf", &pos.x,&pos.y,&pos.z,&u.x,&u.y,&u.z); #endif if (p>0) { /* compute target cell */ cellc = cell_coord(pos); to = PTR_VV(cell_array,cellc,cell_dim); /* enlarge it if necessary */ if (to->n >= to->n_max) alloc_cell(to,to->n_max+CSTEP); /* put the data */ to->ort[to->n] = pos; to->dsp[to->n] = u; to->n++; natoms++; } } fclose(infile); }
void test_car_cdr() { //constructing ('a' . 'b') Cell *cell = alloc_cell(); cell->car.type = CHAR_CELL; cell->cdr.type = CHAR_CELL; cell->car.data.char_value = 'a'; cell->cdr.data.char_value = 'b'; Atom *car_a = &cell->car; Atom *cdr_a = &cell->cdr; g_assert(car(cell) == car_a); g_assert(cdr(cell) == cdr_a); cell->cdr.type = INTEGER_CELL; g_assert_cmpint(car_type(cell), ==, CHAR_CELL); g_assert_cmpint(cdr_type(cell), ==, INTEGER_CELL); }
void copy_cell( int j, int k, int l, int m ) { int i, tmp_n; cell *from, *to; from = PTR_2D_V(cell_array, j, k, cell_dim); to = PTR_2D_V(cell_array, l, m, cell_dim); tmp_n = from->n; if (tmp_n > to->n_max) { to->n = 0; alloc_cell(to, tmp_n); } to->n = tmp_n; for (i=0; i<to->n; ++i) { ORT(to,i,X) = ORT(from,i,X); ORT(to,i,Y) = ORT(from,i,Y); #ifndef MONO SORTE(to,i) = SORTE(from,i); #endif } }
void test_sub_eval() { Cell * sub_op = alloc_cell(); set_car_ptr(sub_op, SUB_OP_CELL, NULL); Cell * result = eval(sub_op); //test base case: (-) --> 0 (this isn't normal Lisp behavior) g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, 0); Cell * one = alloc_int_cell(1); set_cdr_ptr(sub_op, LIST_CELL, one); result = eval(sub_op); //test other base case (- 1) --> -1 g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, -1); Cell * two = alloc_int_cell(2); set_cdr_ptr(one, LIST_CELL, two); result = eval(sub_op); //(- 1 2) --> -1 g_assert_cmpint(car_type(result), ==, INTEGER_CELL); g_assert_cmpint(result->car.data.int_value, ==, -1); Cell * three = alloc_int_cell(3); set_cdr_ptr(two, LIST_CELL, three); result = eval(sub_op); //(- 1 2 3) --> -4 g_assert_cmpint(result->car.data.int_value, ==, -4); }
void lb_relocateParticles(ivektor oldOffset, ivektor oldSize, cell* oldCells){ int x,y,z, x2, y2, z2, i, to_cpu; cell *cell_new, *cell_old; msgbuf *buf; int *numCellsToSend = malloc(num_cpus*sizeof *numCellsToSend); int *numCellsToReceive = malloc(num_cpus*sizeof *numCellsToReceive); if (numCellsToSend == NULL || numCellsToReceive == NULL) error("Cannot allocate send/recv Buffer in lb_relocateParticles"); for (x = 0; x < num_cpus; x++){ numCellsToReceive[x] = 0; numCellsToSend[x] = 0; } /*Count how many cells have been lost to which domain*/ for (x=0; x<cell_dim.x; ++x){ for (y=0; y<cell_dim.y; ++y){ for (z=0; z<cell_dim.z; ++z){ cell_new = PTR_3D_V(cell_array, x, y, z, cell_dim); x2 = x+lb_cell_offset.x-oldOffset.x; y2 = y+lb_cell_offset.y-oldOffset.y; z2 = z+lb_cell_offset.z-oldOffset.z; cell_old = lb_accessCell(oldCells, x2, y2, z2, oldSize); /*Cell changed from real to buffer*/ if (cell_old != NULL && cell_old->lb_cell_type == LB_REAL_CELL && cell_new->lb_cell_type != LB_REAL_CELL){ numCellsToSend[cell_new->lb_cpu_affinity]++; } } } } /* Count how many cells have been gained from which domain*/ for (x=0; x<oldSize.x; ++x){ for (y=0; y<oldSize.y; ++y){ for (z=0; z<oldSize.z; ++z){ cell_old = PTR_3D_V(oldCells, x, y, z, oldSize); x2 = x-lb_cell_offset.x+oldOffset.x; y2 = y-lb_cell_offset.y+oldOffset.y; z2 = z-lb_cell_offset.z+oldOffset.z; cell_new = lb_accessCell(cell_array,x2,y2,z2,cell_dim); if (cell_old->lb_cell_type == LB_REAL_CELL && cell_new == NULL){ error("Cannot relocate cell, new cell is null\n"); } /*Cell changed from real to buffer*/ if (cell_new != NULL && cell_old->lb_cell_type != LB_REAL_CELL && cell_new->lb_cell_type == LB_REAL_CELL){ numCellsToReceive[cell_old->lb_cpu_affinity]++; } } } } /*Allocate buffer for send & receive*/ msgbuf *sendBuf = NULL; memalloc(&sendBuf, num_cpus, sizeof(msgbuf), sizeof(void*), 0, 1, "sendBuf"); msgbuf *recvBuf = NULL; memalloc(&recvBuf, num_cpus, sizeof(msgbuf), sizeof(void*), 0, 1, "recvBuf"); int numSendTo = 0; int numReceiveFrom = 0; if (sendBuf == NULL || recvBuf == NULL) error("Cannot allocate send/recv Buffer in lb_relocateParticles"); for (x = 0; x < num_cpus; x++){ if (numCellsToReceive[x] != 0) { alloc_msgbuf(&recvBuf[x], atom_size*numCellsToReceive[x]*lb_largest_cell); numReceiveFrom++; } if (numCellsToSend[x] != 0){ alloc_msgbuf(&sendBuf[x], atom_size*numCellsToSend[x]*lb_largest_cell); numSendTo++; } } /*Put everything in the buffer*/ /*new geometry is valid, now copy the content from the old to the new domains*/ for (x=1; x<cell_dim.x-1; ++x){ for (y=1; y<cell_dim.y-1; ++y){ for (z=1; z<cell_dim.z-1; ++z){ cell_new = PTR_3D_V(cell_array, x, y, z, cell_dim); if(cell_new->lb_cell_type == LB_REAL_CELL){ x2 = x+lb_cell_offset.x-oldOffset.x; y2 = y+lb_cell_offset.y-oldOffset.y; z2 = z+lb_cell_offset.z-oldOffset.z; cell_old = lb_accessCell(oldCells,x2,y2,z2,oldSize); if (cell_old->lb_cell_type == LB_REAL_CELL){ /*Alloc new cell and copy content from old*/ alloc_cell(cell_new, cell_old->n_max); for (i=0; i<cell_old->n; ++i){ copy_atom_cell_cell(cell_new, cell_new->n, cell_old, i); ++cell_new->n; } alloc_cell(cell_old, 0); } } } } } /*Send data from cells that transformed from real cells to buffer cells*/ /*to the CPUs that now hold this data as a real cell*/ for (x=0; x<cell_dim.x; ++x){ for (y=0; y<cell_dim.y; ++y){ for (z=0; z<cell_dim.z; ++z){ cell_new = PTR_3D_V(cell_array, x, y, z, cell_dim); x2 = x+lb_cell_offset.x-oldOffset.x; y2 = y+lb_cell_offset.y-oldOffset.y; z2 = z+lb_cell_offset.z-oldOffset.z; cell_old = lb_accessCell(oldCells,x2,y2,z2,oldSize); /*Cell changed from real to buffer*/ if (cell_old != NULL && cell_old->lb_cell_type == LB_REAL_CELL && cell_new->lb_cell_type != LB_REAL_CELL){ to_cpu = cell_new->lb_cpu_affinity; buf = &sendBuf[to_cpu]; for (i=0; i<cell_old->n; i++) { copy_one_atom(buf, to_cpu, cell_old, i, 0); #ifdef CLONE int clone; if (l < cell_old->n-nclones) for (clone=1; clone<nclones; clone++) copy_one_atom( buf, to_cpu, cell_old, i+clone, 0); else /* we are dealing with the last in the stack */ for (clone=1; clone<nclones; clone++) copy_one_atom( buf, to_cpu, cell_old, i, 0); #endif } } } } } /*Send/receive buffers*/ int totalOperations = numReceiveFrom + numSendTo; MPI_Request *requests = malloc(totalOperations * sizeof *requests); int *indices = malloc(totalOperations * sizeof *indices); MPI_Status stat; x = 0; for (i = 0; i < num_cpus; ++i) { /*Send data away*/ if (numCellsToSend[i] != 0){ isend_buf(&sendBuf[i], i, &requests[x]); indices[x++] = -1; } /*Start receiving data*/ if (numCellsToReceive[i] != 0){ irecv_buf(&recvBuf[i], i, &requests[x]); indices[x++] = i; } } /*Receive and process data as soon as something is available*/ for (i = totalOperations; i>0; i--){ int finished; MPI_Waitany(i, requests, &finished, &stat); int ind = indices[finished]; if (ind != -1){ MPI_Get_count(&stat, REAL, &recvBuf[ind].n); process_buffer( &recvBuf[ind]); } requests[finished] = requests[i-1]; indices[finished] = indices[i-1]; } free(requests); free(indices); /*Clean up*/ for (x = 0; x < num_cpus; x++){ if (numCellsToReceive[x] != 0) free_msgbuf(&recvBuf[x]); if (numCellsToSend[x] != 0) free_msgbuf(&sendBuf[x]); } free(numCellsToSend); free(numCellsToReceive); }
VALUE build_matrix(char *buf, int bufsize) { int str_start = 0; int num_rows = 1; int quote_count = 0, quotes_matched = 1; struct s_Row *first_row = alloc_row(0); struct s_Row *cur_row = first_row; struct s_Cell *cur_cell = cur_row->first_cell; cur_cell->start = buf; VALUE matrix; char *cur; if (bufsize > 0 && *(buf+bufsize-1) == '\n') { *(buf+bufsize-1) = 0; --bufsize; } for (cur = buf; cur < buf+bufsize; cur++) { if (*cur == '"') { if (0 == quote_count && cur_cell->start != cur) /* Quotes begin past opening of cell */ rb_raise(BAMFCSV_MalformedCSVError_class, "Illegal quoting on line %d, cell %d: Quoted cell must open with '\"'", num_rows, cur_row->cell_count); else ++quote_count; } quotes_matched = !(quote_count & 1); /* count is even */ if (quotes_matched) { if (*cur == ',') { if (quote_count && *(cur-1) != '"') rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d.", num_rows, cur_row->cell_count); finalize_cell(cur_cell, cur, quote_count); cur_cell = alloc_cell(cur_row, cur_cell); cur_cell->start = cur+1; quote_count = 0; } else if (*cur == '\n') { if (quote_count && !(*(cur-1) == '"' || *(cur-1) == '\r' && *(cur-2) == '"')) rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d: EOL", num_rows, cur_row->cell_count); finalize_cell(cur_cell, cur, quote_count); cur_row = alloc_row(cur_row); cur_cell = cur_row->first_cell; cur_cell->start = cur+1; quote_count = 0; num_rows++; } else if (quote_count && *cur != '\r' && *cur != '"') rb_raise(BAMFCSV_MalformedCSVError_class, "Illegal quoting on line %d, cell %d", num_rows, cur_row->cell_count); } } if (!quotes_matched) /* Reached EOF without matching quotes */ rb_raise(BAMFCSV_MalformedCSVError_class, "Illegal quoting on line %d, cell %d: File ends without closing '\"'", num_rows, cur_row->cell_count); else if (quote_count && *(cur-1) != '"') /* Quotes closed before end of final cell */ rb_raise(BAMFCSV_MalformedCSVError_class, "Unclosed quoted field on line %d, cell %d: EOF", num_rows, cur_row->cell_count); finalize_cell(cur_cell, cur, quote_count); matrix = build_matrix_from_pointer_tree(first_row, num_rows); free_row(first_row); return matrix; }
void generate_qc( void ) { real c=0.80,d=0.5; /* constants */ int a1,a2,a3,a4,a5,a6,a7,a8; /* grid boundaries */ int hv,i,j; /* auxiliary variables */ int p[3],q[3]; /* approximant */ int no,np,na,nb,nc,nt; /* geometry numbers */ real tau[3],betrag[3],tau0[3],tau1[3]; /* grid vectors */ real perkah[3]; /* period in grid space */ real tautl; /* golden number */ real tautl0,tautl1,betrtl; /* tiling vectors (lt) */ real box[3]; vektor cen; /* cell center */ vektor perpro; /* per pe */ #ifndef BUFCELLS ivektor cpu_dim; int num_cpus = 0; int myid = 0; ivektor my_coord; /* this can't possibly work... */ cpu_dim.x=1; cpu_dim.y=1; cpu_dim.z=1; /* this can't possibly work... */ my_coord.x=0; my_coord.y=0; my_coord.z=0; #endif tautl = (sqrt(5.0)+1.0)*0.5; gam[0]=0.14;gam[1]=-0.25;gam[2]=0.33;gam[3]=-0.41;gam[4]=0.52;gam[5]=-0.33; num_sort[0]=0;num_sort[1]=0;num_sort[2]=0; /* generating grid vectors */ for (j=0;j<3;j++) { p[j] =1;q[j]=0;hv=0; for (i=0;i<appr[j];i++) { hv=q[j]; q[j]=p[j]; p[j]=p[j]+hv; } tau[j]=((real) p[j])/((real) q[j]); perkah[j]=(tautl*p[j]+q[j])/sqrt(tautl+2.0); #ifdef MPI if (0==myid) { printf("p(%1d)= %3d,q(%1d)= %3d,tau(%1d)= %3f\n", j,p[j],j,q[j],j,tau[j]); printf("period in atomic units %10.5f\n",perkah[j]); }; #endif } for (i=0;i<3;i++) { betrag[i]=sqrt(tau[i]*tau[i]+1.0); tau0[i]=tau[i]/betrag[i]; tau1[i]=1.0/betrag[i]; } gx[0]= tau0[0];gy[0]= 0; gz[0]=-tau1[2]; gx[1]= tau1[0];gy[1]= tau0[1];gz[1]= 0; gx[2]= 0; gy[2]= tau1[1];gz[2]= tau0[2]; gx[3]= 0; gy[3]=-tau1[1];gz[3]= tau0[2]; gx[4]= tau1[0];gy[4]=-tau0[1];gz[4]= 0; gx[5]= tau0[0];gy[5]= 0; gz[5]= tau1[2]; /* generating sort tiling vectors */ betrtl=sqrt(tautl+2.0); tautl0=tautl/betrtl;tautl1=1.0/betrtl; tx[0]= tautl0;ty[0]= 0; tz[0]=-tautl1; tx[1]= tautl1;ty[1]= tautl0;tz[1]= 0; tx[2]= 0; ty[2]= tautl1;tz[2]= tautl0; tx[3]= 0; ty[3]=-tautl1;tz[3]= tautl0; tx[4]= tautl1;ty[4]=-tautl0;tz[4]= 0; tx[5]= tautl0;ty[5]= 0; tz[5]= tautl1; /* distributing computation */ gmin.x=-perkah[0];gmax.x=perkah[0]; gmin.y=-perkah[1];gmax.y=perkah[1]; gmin.z=-perkah[2];gmax.z=perkah[2]; perpro.x=(gmax.x-gmin.x)/((real) cpu_dim.x); perpro.y=(gmax.y-gmin.y)/((real) cpu_dim.y); perpro.z=(gmax.z-gmin.z)/((real) cpu_dim.z); for (i=0;i<3;i++) { box[i]=4.0*perkah[i]; iper[i]=1.0/box[i]; } /* Set up 1 atom input cell */ input = (cell *) malloc(sizeof(cell)); if (0==input) error("Can't allocate input cell.") ; input->n_max=0; alloc_cell(input, 1); /* Set up cpu parts */ cen.x=(2.*my_coord.x-cpu_dim.x+1.)*perpro.x*0.5*d; lmin.x=cen.x-perpro.x*0.5-c; lmax.x=cen.x+perpro.x*0.5+c; lmin.x=MAX(lmin.x,gmin.x); lmax.x=MIN(lmax.x,gmax.x); perm[0]=2.0*(my_coord.x*perpro.x); perp[0]=perm[0]+2.0*perpro.x; cen.y=(2.*my_coord.y-cpu_dim.y+1.)*perpro.y*0.5*d; lmin.y=cen.y-perpro.y*0.5-c; lmax.y=cen.y+perpro.y*0.5+c; lmin.y=MAX(lmin.y,gmin.y); lmax.y=MIN(lmax.y,gmax.y); perm[1]=2.0*(my_coord.y*perpro.y); perp[1]=perm[1]+2.0*perpro.y; cen.z=(2.*my_coord.z-cpu_dim.z+1.)*perpro.z*0.5*d; lmin.z=cen.z-perpro.z*0.5-c; lmax.z=cen.z+perpro.z*0.5+c; lmin.z=MAX(lmin.z,gmin.z); lmax.z=MIN(lmax.z,gmax.z); perm[2]=2.0*(my_coord.z*perpro.z); perp[2]=perm[2]+2.0*perpro.z; /* computing basic grid border parameters */ for (j=0;j<6;j++) { a1=floor(gx[j]*lmin.x+gy[j]*lmin.y+gz[j]*lmin.z-gam[j]+0.5); a2=floor(gx[j]*lmax.x+gy[j]*lmax.y+gz[j]*lmax.z-gam[j]+0.5); a3=floor(gx[j]*lmin.x+gy[j]*lmax.y+gz[j]*lmin.z-gam[j]+0.5); a4=floor(gx[j]*lmax.x+gy[j]*lmin.y+gz[j]*lmax.z-gam[j]+0.5); a5=floor(gx[j]*lmin.x+gy[j]*lmin.y+gz[j]*lmax.z-gam[j]+0.5); a6=floor(gx[j]*lmax.x+gy[j]*lmax.y+gz[j]*lmin.z-gam[j]+0.5); a7=floor(gx[j]*lmin.x+gy[j]*lmax.y+gz[j]*lmax.z-gam[j]+0.5); a8=floor(gx[j]*lmax.x+gy[j]*lmin.y+gz[j]*lmin.z-gam[j]+0.5); k1min[j]=MIN(MIN(MIN(a1,a2),MIN(a3,a4)),MIN(MIN(a5,a6),MIN(a7,a8))); k1max[j]=MAX(MAX(MAX(a1,a2),MAX(a3,a4)),MAX(MAX(a5,a6),MAX(a7,a8))); } natoms=0; nactive=0; borders(); adjust(); printf("Number of PE, number of atoms: %d %d\n",myid,natoms); }
void test_alloc_cell() { Cell *cell = alloc_cell(); g_assert_cmpint(cell->car.type, ==, UNKOWN_CELL); g_assert_cmpint(cell->cdr.type, ==, UNKOWN_CELL); }