void DialupProperties::setNumber(const QString &number) { insert(NUMBER_TAG, number); }
quotient_filter(InputIt first, InputIt last, size_type slot_count = 0, const Hash &hash = Hash()) : quotient_filter(slot_count, hash) { insert(first, last); }
void faceSet::sync(const polyMesh& mesh) { const polyBoundaryMesh& patches = mesh.boundaryMesh(); label nAdded = 0; if (Pstream::parRun()) { // Send faces in set that are on a processorPatch. Send as patch face // indices. forAll(patches, patchI) { const polyPatch& pp = patches[patchI]; if (isA<processorPolyPatch>(pp)) { const processorPolyPatch& procPatch = refCast<const processorPolyPatch>(pp); // Convert faceSet locally to labelList. DynamicList<label> setFaces(pp.size()); forAll(pp, i) { if (found(pp.start() + i)) { setFaces.append(i); } } setFaces.shrink(); OPstream toNeighbour ( Pstream::blocking, procPatch.neighbProcNo() ); toNeighbour << setFaces; } } // Receive forAll(patches, patchI) { const polyPatch& pp = patches[patchI]; if (isA<processorPolyPatch>(pp)) { const processorPolyPatch& procPatch = refCast<const processorPolyPatch>(pp); IPstream fromNeighbour ( Pstream::blocking, procPatch.neighbProcNo() ); labelList setFaces(fromNeighbour); forAll(setFaces, i) { if (insert(pp.start() + setFaces[i])) { nAdded++; } } } } } // Couple cyclic patches forAll (patches, patchI) { const polyPatch& pp = patches[patchI]; if (isA<cyclicPolyPatch>(pp)) { const cyclicPolyPatch& cycPatch = refCast<const cyclicPolyPatch>(pp); forAll (cycPatch, i) { label thisFaceI = cycPatch.start() + i; label otherFaceI = cycPatch.transformGlobalFace(thisFaceI); if (found(thisFaceI)) { if (insert(otherFaceI)) { nAdded++; } } else if (found(otherFaceI)) { if (insert(thisFaceI)) { nAdded++; } } } } }
static void parsedefinition(bool globallevel) { Cell *head; int globaltokenoffside = tokenindent, posCode; bool generic = False; if(tokentype == ABSTYPE && globallevel) { parseabstype(); while(tokentype == SEP) gettoken(); return; } else if(tokentype == GENERIC && globallevel) { generic = True; gettoken(); } parselefthandside(); posCode = getPositionCode(); tokenoffside = tokenindent + 1; if(tokentype == COLONS && globallevel) { head = pop(); if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(13); gettoken(); parsetype(TYPEEXPR); if(!inserttypeexpr(getfunction(head->value)->name, pop())) parseerror(12); getfunction(head->value)->generic = generic; while(tokentype == SEP) gettoken(); } else if(tokentype == DEF && globallevel) { parsestructdef(); while(tokentype == SEP) gettoken(); } else if(tokentype == SYN && globallevel) { parsetypesynonym(); while(tokentype == SEP) gettoken(); } else { head = top(); if(head->tag == APPLY || globallevel) { for(; head->tag==APPLY; head=head->left) checkpattern(head->right); if(head->tag != UNDEFINED && head->tag != FUNC) parseerror(17); if(globallevel) storefunctionname(getfunction(head->value)->name); } else checkpattern(head); parseexpressionclause(); if(tokentype == WHERE) { gettoken(); parsewhereclause(); } else if(tokentype == offside) { tokenoffside = globaltokenoffside; gettoken(); if(tokentype == WHERE) { tokenoffside = tokenindent + 1; gettoken(); parsewhereclause(); } } makeinverse(LIST); top()->value = posCode; if(globallevel) { Cell *def = pop(); int argcount = 0; char *funname; head = def; for(head=head->left; head->tag==APPLY; head=head->left) argcount++; funname = getfunction(head->value)->name; initrename(funname); def = renamerec(FUN, def); if(!insert(funname, argcount, FUNC, def, NULL)) parseerror(18); } } }
void insert(std::initializer_list<value_type> ilist) { insert(ilist.begin(), ilist.end()); }
int main() { node * curr; char input[15]; printf("Creating binary tree..."); makeempty(); printf("\tDone\n\n"); char delims[] = " "; char *result = NULL; char *item = NULL; while (1){ printf("What would you like to do?\n[help for list of commands]\n"); gets(input); search_count = 0; result = (char *) strtok( input, delims ); if(!strcmp("insert", result)) { item = (char *) strtok( NULL, delims ); if( !find(root, atoi(item)) ) { curr = (node *)malloc(sizeof(node)); curr->left = curr->right = NULL; curr->val = atoi(item); insert(&root, curr); printout(root); } else printf("Value %d exists\n\n", atoi(item)); continue; } if(!strcmp("delete", result)) { item = (char *) strtok( NULL, delims ); if( find(root, atoi(item)) ) { printf("Found value %d \n", atoi(item)); deleteval( root , atoi(item) ); printf("Value %d deleted\n\n", atoi(item)); } else printf("Value %d does not exist\n\n", atoi(item)); continue; } if(!strcmp("search", result)) { item = (char *) strtok( NULL, delims ); if( find(root, atoi(item)) ) { printf("Found value %d - %d nodes walked\n\n", atoi(item), search_count); } else printf("Value %d does not exist\n\n", atoi(item)); continue; } if(!strcmp("max", result)) { if(root != NULL) printf("Max value: %d\n\n", max(root)); else printf("Search tree is empty\n\n"); continue; } if(!strcmp("succ", result)) { item = (char *) strtok( NULL, delims ); int x, tree_max; if( root == NULL ) { printf("Search tree is empty\n\n"); continue; } x = succ( root , atoi(item) , NULL); if(x==NULL) { printf("Value %d is larger than any other value in tree\n\n", atoi(item)); continue; //printf("Value's %d next larger value is %d\n\n", atoi(item) , x ); } else if ( x == atoi(item) ) { printf("Value %d is the largest value in tree\n\n", atoi(item)); continue; //printf("Value's %d next larger value is %d\n\n", atoi(item) , x ); } else { printf("Value %d is the next larger value of %d\n\n", x , atoi(item)); continue; } continue; } if(!strcmp("subtree", result)){ result = strtok( NULL, delims ); if(!strcmp("leaves", result)){ item = (char *) strtok( NULL, delims ); if( find(root, atoi(item)) ) { find_print(root, atoi(item)); } else printf("Value %d does not exist\n\n", atoi(item)); continue; } else { printf("Please give a valid command\n\n"); continue; } } if(!strcmp("exit", result)){ printf("Destroing tree...\t"); //printf("\n"); tree_destroy(root); printf("Done\n\n"); printf("Bye bye!\n\n\n"); break; } if(!strcmp("help", result)){ printf("\nList of commands: \ninsert x \ndelete x \nsearch x \nmax \nsucc x \nsubtree leaves x \nexit \n\n"); continue; } printf("Please give a valid command\n\n"); } //sleep(1000); return 0; }
void UEFITool::insertBefore() { insert(CREATE_MODE_BEFORE); }
void run() { // insert documents with a: 1 and b: 1 for (size_t i = 0; i < 1000; ++i) { insert(BSON("a" << 1 << "b" << 1)); } // insert documents with a: 1 and b: 2 for (size_t i = 0; i < 1000; ++i) { insert(BSON("a" << 1 << "b" << 2)); } // insert documents with a: 2 and b: 1 for (size_t i = 0; i < 1000; ++i) { insert(BSON("a" << 2 << "b" << 1)); } // insert documents with a: 2 and b: 3 for (size_t i = 0; i < 1000; ++i) { insert(BSON("a" << 2 << "b" << 3)); } addIndex(BSON("a" << 1 << "b" << 1)); AutoGetCollectionForReadCommand ctx(&_opCtx, nss); Collection* coll = ctx.getCollection(); std::vector<const IndexDescriptor*> indices; coll->getIndexCatalog()->findIndexesByKeyPattern( &_opCtx, BSON("a" << 1 << "b" << 1), false, &indices); ASSERT_EQ(1U, indices.size()); DistinctParams params{&_opCtx, indices[0]}; params.scanDirection = 1; params.fieldNo = 1; params.bounds.isSimpleRange = false; OrderedIntervalList aOil{"a"}; aOil.intervals.push_back(IndexBoundsBuilder::allValues()); params.bounds.fields.push_back(aOil); OrderedIntervalList bOil{"b"}; bOil.intervals.push_back(IndexBoundsBuilder::allValues()); params.bounds.fields.push_back(bOil); WorkingSet ws; DistinctScan distinct(&_opCtx, std::move(params), &ws); WorkingSetID wsid; PlanStage::StageState state; std::vector<int> seen; while (PlanStage::IS_EOF != (state = distinct.work(&wsid))) { ASSERT_NE(PlanStage::FAILURE, state); if (PlanStage::ADVANCED == state) { seen.push_back(getIntFieldDotted(ws, wsid, "b")); } } ASSERT_EQUALS(4U, seen.size()); ASSERT_EQUALS(1, seen[0]); ASSERT_EQUALS(2, seen[1]); ASSERT_EQUALS(1, seen[2]); ASSERT_EQUALS(3, seen[3]); }
void list<Object>::push_front( const Object & x ) { insert( begin( ), x ); }
void FlowArray::copy_from( const FlowArray& array) { int i; a_size = 0; for ( i = 0; i < array.a_size; i++) { switch( array.a[i]->type()) { case flow_eObjectType_Node: { FlowNode *n = new FlowNode(); n->copy_from(*(FlowNode *)array.a[i]); insert( n); break; } default: ; } } for ( i = 0; i < array.a_size; i++) { switch( array.a[i]->type()) { case flow_eObjectType_Con: { /* Both source and destination has to be members */ FlowNode *dest_node = 0; FlowNode *source_node = 0; for ( int j = 0, k = 0; j < array.a_size; j++) { switch( array.a[j]->type()) { case flow_eObjectType_Node: { if ( array.a[j] == ((FlowCon *)array.a[i])->destination()) dest_node = (FlowNode *)a[k]; if ( array.a[j] == ((FlowCon *)array.a[i])->source()) source_node = (FlowNode *)a[k]; k++; break; } default: ; } } if ( dest_node && source_node) { FlowCon *n = new FlowCon(*(FlowCon *)array.a[i], source_node, dest_node); insert( n); } break; } case flow_eObjectType_Line: { FlowLine *n = new FlowLine(*(FlowLine *)array.a[i]); insert( n); break; } case flow_eObjectType_Arc: { FlowArc *n = new FlowArc(*(FlowArc *)array.a[i]); insert( n); break; } case flow_eObjectType_Rect: { FlowRect *n = new FlowRect(*(FlowRect *)array.a[i]); insert( n); break; } case flow_eObjectType_Text: { FlowText *n = new FlowText(*(FlowText *)array.a[i]); insert( n); break; } case flow_eObjectType_Pixmap: { FlowPixmap *n = new FlowPixmap(*(FlowPixmap *)array.a[i]); insert( n); break; } case flow_eObjectType_AnnotPixmap: { FlowAnnotPixmap *n = new FlowAnnotPixmap(*(FlowAnnotPixmap *)array.a[i]); insert( n); break; } case flow_eObjectType_AnnotPixmapButton: { FlowAnnotPixmapButton *n = new FlowAnnotPixmapButton(*(FlowAnnotPixmapButton *)array.a[i]); insert( n); break; } case flow_eObjectType_Radiobutton: { FlowRadiobutton *n = new FlowRadiobutton(*(FlowRadiobutton *)array.a[i]); insert( n); break; } default: ; } } }
void FlowArray::open( void *ctx, ifstream& fp) { int type; int end_found = 0; char dummy[40]; for (;;) { fp >> type; switch( type) { case flow_eSave_Array: break; case flow_eSave_Rect: { FlowRect *n = new FlowRect( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_Line: { FlowLine *n = new FlowLine( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_Arc: { FlowArc *n = new FlowArc( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_Text: { FlowText *n = new FlowText( (FlowCtx *) ctx, ""); n->open( fp); insert( n); break; } case flow_eSave_Pixmap: { FlowPixmap *n = new FlowPixmap( (FlowCtx *) ctx, (flow_sPixmapData *) NULL); n->open( fp); insert( n); break; } case flow_eSave_AnnotPixmap: { FlowAnnotPixmap *n = new FlowAnnotPixmap( (FlowCtx *) ctx, 0); n->open( fp); insert( n); break; } case flow_eSave_AnnotPixmapButton: { FlowAnnotPixmapButton *n = new FlowAnnotPixmapButton( (FlowCtx *) ctx, 0); n->open( fp); insert( n); break; } case flow_eSave_Radiobutton: { FlowRadiobutton *n = new FlowRadiobutton( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_NodeClass: { FlowNodeClass *n = new FlowNodeClass( (FlowCtx *) ctx, ""); n->open( fp); insert( n); break; } case flow_eSave_ConClass: { FlowConClass *n = new FlowConClass( (FlowCtx *) ctx, "", flow_eConType_Straight, flow_eCorner_Right, flow_eDrawType_Line, 1); n->open( fp); insert( n); break; } case flow_eSave_ConPoint: { FlowConPoint *n = new FlowConPoint( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_Annot: { FlowAnnot *n = new FlowAnnot( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_Arrow: { FlowArrow *n = new FlowArrow( (FlowCtx *) ctx,0,0,0,0,0,0,flow_eDrawType_Line); n->open( fp); insert( n); break; } case flow_eSave_Node: { FlowNode *n = new FlowNode( (FlowCtx *) ctx, "", 0, 0, 0); n->open( fp); insert( n); break; } case flow_eSave_Con: { int sts; FlowCon *n = new FlowCon( (FlowCtx *) ctx, "", (FlowConClass *)0, (FlowNode *)0, (FlowNode *)0, 0, 0, &sts); n->open( fp); insert( n); break; } case flow_eSave_Point: { FlowPoint *n = new FlowPoint( (FlowCtx *) ctx); n->open( fp); insert( n); break; } case flow_eSave_End: end_found = 1; break; default: cout << "FlowArray:open syntax error" << endl; fp.getline( dummy, sizeof(dummy)); } if ( end_found) break; } }
void add_matrix(Crosslist * mat1, Crosslist * mat2, Crosslist * mat3) { int m = mat1->rows; int n = mat1->cols; mat3->rows = m; mat3->cols = n; mat3->rhead = (Link *) malloc((m + 1) * sizeof(Link)); mat3->chead = (Link *) malloc((n + 1) * sizeof(Link)); int x; for (x = 0; x < mat3->rows + 1; x++) mat3->rhead[x] = NULL; for (x = 0; x < mat3->cols + 1; x++) mat3->chead[x] = NULL; struct node *p1, *p2; int i; for (i = 1; i < mat1->rows + 1; i++) { p1 = mat1->rhead[i]; p2 = mat2->rhead[i]; while (p1 != NULL && p2 != NULL) { if (p1->j < p2->j) { struct node *temp = (struct node *) malloc(sizeof(struct node)); *temp = *p1; insert(mat3, temp); p1 = p1->right; } else if (p1->j > p2->j) { struct node *temp = (struct node *) malloc(sizeof(struct node)); *temp = *p2; insert(mat3, temp); p2 = p2->right; } else if (p1->e + p2->e != 0) { struct node *temp = (struct node *) malloc(sizeof(struct node)); temp->i = p1->i; temp->j = p1->j; temp->e = p1->e + p2->e; insert(mat3, temp); p1 = p1->right; p2 = p2->right; } else { p1 = p1->right; p2 = p2->right; } } while (p1 != NULL) { struct node *temp = (struct node *) malloc(sizeof(struct node)); *temp = *p1; insert(mat3, temp); p1 = p1->right; } while (p2 != NULL) { struct node *temp = (struct node *) malloc(sizeof(struct node)); *temp = *p2; insert(mat3, temp); p2 = p2->right; } } }
void DialupProperties::setPassword(const QString & password) { insert(PASSWORD_TAG, password); }
void DialupProperties::setUsername(const QString &username) { insert(USERNAME_TAG, username); }
uSHORT dptBuffer_S::netInsert(uLONG inData) { uLONG temp = NET_SWAP_4(inData); return (insert(&temp, sizeof(uLONG))); }
void list<Object>::push_back( const Object & x ) { insert( end( ), x ); }
uSHORT dptBuffer_S::netInsert(uSHORT inData) { uSHORT temp = NET_SWAP_2(inData); return (insert(&temp, sizeof(uSHORT))); }
Test_RepresentationSolverSeries() { insert(this); }
void UEFITool::insertInto() { insert(CREATE_MODE_PREPEND); }
Test_LexicographicalEvaluation() { insert(this); }
void UEFITool::insertAfter() { insert(CREATE_MODE_AFTER); }
void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, const TType *ptype1, const TType *ptype2, const TType *ptype3, const TType *ptype4, const TType *ptype5) { if (ptype1->getBasicType() == EbtGSampler2D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler3D) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSamplerCube) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); } else if (ptype1->getBasicType() == EbtGSampler2DArray) { bool gvec4 = (rvalue->getBasicType() == EbtGVec4); insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); } else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4)); } else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) { ASSERT(!ptype4 && !ptype5); insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4)); } else { TFunction *function = new TFunction(NewPoolTString(name), rvalue, op, ext); function->addParameter(TConstParameter(ptype1)); if (ptype2) { function->addParameter(TConstParameter(ptype2)); } if (ptype3) { function->addParameter(TConstParameter(ptype3)); } if (ptype4) { function->addParameter(TConstParameter(ptype4)); } if (ptype5) { function->addParameter(TConstParameter(ptype5)); } insert(level, function); } }
void insert(InputIt first, InputIt last) { std::for_each(first, last, [this](const_reference elem) { insert(elem); }); }
//默认作为末元素插入 Rank insert ( T const& e ) { return insert ( _size, e ); }
std::pair<iterator, bool> emplace(Args &&... args) { value_type temp(std::forward<Args>(args)...); return insert(temp); }
void insert_before(el<T>* ptr, const T& dt){ insert(ptr->prev, dt); }
int main(void) { int loop = 0; int i; char *org_word; char* input[COUNT] = {"?", "12", "11", "22", "?1??2???1", "???", "1?2", "??1", "1??1", "1???1", "1??????12?"}; char* inputs[COUNT]; for(i = 0; i < COUNT; i++) { inputs[i] = (char *)malloc(WORD_MAX); strcpy(inputs[i], input[i]); } org_word = (char*)malloc(WORD_MAX); while (loop < COUNT) { int sub_loop = 0; int result = RIGHT_WORD; int str_len = strlen(inputs[loop]); char *result_str = NULL; WORD_REC wr; wr.jaum = 0; wr.moum = 0; memset(org_word, 0x0, WORD_MAX); strcpy(org_word, inputs[loop]); if(str_len == 1) { result = RIGHT_WORD; } else { while(sub_loop < str_len) { char *current = &inputs[loop][sub_loop]; if(*current == '1') { if(++wr.jaum >= 2) { result = WRONG_WORD; break; } else { wr.moum = 0; } } else if (*current == '2') { if(++wr.moum >= 2) { result = WRONG_WORD; break; } else { wr.jaum = 0; } } else if (*current == '?') { wr.moum = 0; wr.jaum = 0; result = UNKNOWN_WORD; #ifdef DEBUG_MODE printf("index: %d, current: %c --> ", sub_loop, *current); #endif if(insert(current)) { #ifdef DEBUG_MODE printf("%c\n", *current); #endif sub_loop = 0; continue; } #ifdef DEBUG_MODE printf("cannot insert\n"); #endif sub_loop++; continue; } #ifdef DEBUG_MODE printf("index: %d, current: %c\n", sub_loop, *current); #endif sub_loop++; } } if(result == WRONG_WORD) { result_str = "wrong word"; } else if(result == RIGHT_WORD) { result_str = "right word"; } else { result_str = "unknown word"; } #ifdef DEBUG_MODE printf("%s (%s) : %s\n", org_word, inputs[loop], result_str); #else printf("%s : %s\n", org_word, result_str); #endif loop++; } free(org_word); for(i = 0; i < COUNT; i++) { free(inputs[i]); } return 0; }
list(const T& dt) { insert(head_, dt); }
int main(int argc, char* argv[]) { int* bodies_off; int* n_bodies_split; int n_local_bodies; const MPI_Comm comm = MPI_COMM_WORLD; FILE *inputf; FILE *outputf; double clockStart, clockEnd; int rc, n_proc, rank; rc = MPI_Init(&argc, &argv); if (rc != MPI_SUCCESS) { puts("MPI_Init failed"); exit(-1); } MPI_Comm_size(comm, &n_proc); MPI_Comm_rank(comm, &rank); //creazione datatype per mpi! MPI_Datatype bodytype; MPI_Datatype type[6] = { MPI_LB, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_UB }; int block_len[6] = {1, 1, 3, 3, 3, 1}; MPI_Aint disp[6]; leaf_t example[2]; MPI_Get_address(&example[0], &disp[0]); MPI_Get_address(&(example[0].mass), &disp[1]); MPI_Get_address(&(example[0].pos), &disp[2]); MPI_Get_address(&(example[0].vel), &disp[3]); MPI_Get_address(&(example[0].acc), &disp[4]); MPI_Get_address(&(example[1].acc), &disp[5]); // int i; // for(i = 6; i >= 0; --i) // disp[i] -= disp[0]; disp[1] = disp[1] - disp[0]; disp[2] = disp[2] - disp[0]; disp[3] = disp[3] - disp[0]; disp[4] = disp[4] - disp[0]; disp[5] = disp[5] - disp[0]; MPI_Type_create_struct(6, block_len, disp, type, &bodytype); MPI_Type_commit(&bodytype); bodies_off = malloc((n_proc + 1) * sizeof(int)); n_bodies_split = malloc((n_proc) * sizeof(int)); bodies = malloc(nbodies * sizeof(node_t*)); leafs = malloc(nbodies * sizeof(leaf_t)); char* inputfile = argv[1]; inputf = fopen(inputfile, "r"); if (inputf == NULL) { printf("impossibile leggere da file"); exit(1); } fscanf(inputf, "%d", &nbodies); fscanf(inputf, "%d", &steps); fscanf(inputf, "%lf", &dt); fscanf(inputf, "%lf", &eps); fscanf(inputf, "%lf", &tol); fclose(inputf); if (rank == 0) { int i; create_bodies(); quicksort(0, nbodies - 1); // bublesort(); // int i = 0; // for (i = 0; i < nbodies; i++) { // printf("%lf, %lf, %lf \n", bodies[i]->pos[0], bodies[i]->pos[1], // bodies[i]->pos[2]); // } n_local_bodies = nbodies / n_proc; //split delle particelle secondo shark & fish // split_bodies(n_proc, bodies_off, n_bodies_split); // n_local_bodies = n_bodies_split[rank]; // // MPI_Bcast(n_bodies_split, n_proc, MPI_INT, 0, comm); MPI_Bcast(leafs, nbodies, bodytype, 0, comm); dthf = 0.5 * dt; epssq = eps * eps; itolsq = 1.0 / (tol * tol); clockStart = MPI_Wtime(); int step = 0; root = NULL; for (step = 0; step < steps; step++) { compute_center_and_diameter(); root = malloc(sizeof(struct node_t)); // "new" is like "malloc" double mass_root = 0.0; root->type = 1; root->mass = &mass_root; root->pos = center; root->cell.childs[0] = NULL; root->cell.childs[1] = NULL; root->cell.childs[2] = NULL; root->cell.childs[3] = NULL; root->cell.childs[4] = NULL; root->cell.childs[5] = NULL; root->cell.childs[6] = NULL; root->cell.childs[7] = NULL; double radius = diameter * 0.5; int i = 0; for (i = 0; i < nbodies; i++) { insert(root, bodies[i], radius); // questo è il modo per passare i dati per riferimento... cioè mandare l'indirizzo della struttura puntata dal puntatore } curr = 0; compute_center_of_mass(&(*root)); for (i = 0; i < n_local_bodies; i++) { compute_force(&(*root), &(*bodies[i]), diameter, step); } // for (i = 0; i < nbodies; i++) { // } deallocate_tree(root); //inserire all gather MPI_Allgather(leafs, n_local_bodies, bodytype, leafs, n_local_bodies, bodytype, comm); for (i = 0; i < nbodies; i++) { advance(&(*bodies[i])); } // int p = 0; // for (p = 0; p < nbodies; p++) // printf("%lf, %lf, %lf \n", bodies[p]->pos[0], bodies[p]->pos[1], // bodies[p]->pos[2]); // printf("*************************************** \n"); } // int i = 0; // dopo l'esecuzione!! // int proc_rec = 1; // while (proc_rec < n_proc) { // MPI_Status status; // int proc_rank; // int cap = nbodies / n_proc; // node_t temp[cap]; // MPI_Recv(temp, cap, bodytype, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, // &status); // proc_rank = status.MPI_SOURCE; // // int idx = 0; // for (idx = proc_rec * (cap); idx < cap; idx++) // *bodies[idx] = temp[idx]; // proc_rec++; // } clockEnd = MPI_Wtime(); if (nbodies == 16384) { system("echo 'Host:' `hostname` >> output16384 "); outputf = fopen("output16384", "a"); fprintf(outputf, "Tempo di esecuzione: %lf \n", clockEnd - clockStart); for (i = 0; i < nbodies; i++) { fprintf(outputf, "%lf, %lf, %lf \n", bodies[i]->pos[0], bodies[i]->pos[1], bodies[i]->pos[2]); } } else if (nbodies == 32768) { system("echo 'Host:' `hostname` >> output32768 "); outputf = fopen("output32768", "a"); fprintf(outputf, "Tempo di esecuzione: %lf \n", clockEnd - clockStart); for (i = 0; i < nbodies; i++) { fprintf(outputf, "%lf, %lf, %lf \n", bodies[i]->pos[0], bodies[i]->pos[1], bodies[i]->pos[2]); } } else if (nbodies == 65536) { system("echo 'Host:' `hostname` >> output65536 "); outputf = fopen("output65536", "a"); fprintf(outputf, "Tempo di esecuzione: %lf \n", clockEnd - clockStart); for (i = 0; i < nbodies; i++) { fprintf(outputf, "%lf, %lf, %lf \n", bodies[i]->pos[0], bodies[i]->pos[1], bodies[i]->pos[2]); } } else { system("echo 'Host:' `hostname` >> output "); outputf = fopen("output", "a"); fprintf(outputf, "Tempo di esecuzione: %lf \n", clockEnd - clockStart); for (i = 0; i < nbodies; i++) { fprintf(outputf, "%lf, %lf, %lf \n", bodies[i]->pos[0], bodies[i]->pos[1], bodies[i]->pos[2]); } } fflush(outputf); fclose(outputf); printf("Esecuzione completata\n"); } else { int low = 1, up = 0; int i; dthf = 0.5 * dt; epssq = eps * eps; itolsq = 1.0 / (tol * tol); // if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT) { // printf("Inizializzazione della libreria di papi fallita \n"); // exit(1); // } // // if (PAPI_create_eventset(&event_set) != PAPI_OK) { // printf("E' andata a male la creazione dell'eventSet \n"); // exit(1); // } // // if (PAPI_add_events(event_set, events, 2) != PAPI_OK) { // printf("E' andata a male l'aggiunta degli eventi\n"); // exit(1); // } n_local_bodies = nbodies / n_proc; MPI_Bcast(leafs, nbodies, bodytype, 0, comm); int step = 0; root = NULL; low += (rank * n_local_bodies); up = low + n_local_bodies; // PAPI_start(event_set); // clockStart = PAPI_get_real_usec(); for (step = 0; step < steps; step++) { compute_center_and_diameter(); root = malloc(sizeof(struct node_t)); // "new" is like "malloc" root->type = 1; *(root->mass) = 0.0; root->pos = center; root->cell.childs[0] = NULL; root->cell.childs[1] = NULL; root->cell.childs[2] = NULL; root->cell.childs[3] = NULL; root->cell.childs[4] = NULL; root->cell.childs[5] = NULL; root->cell.childs[6] = NULL; root->cell.childs[7] = NULL; double radius = diameter * 0.5; for (i = 0; i < nbodies; i++) { bodies[i] = malloc(sizeof(node_t)); bodies[i]->cell.leaf = &leafs[i]; bodies[i]->mass = &leafs[i].mass; bodies[i]->pos = leafs[i].pos; insert(&(*root), &(*bodies[i]), radius); // questo è il modo per passare i dati per riferimento... cioè mandare l'indirizzo della struttura puntata dal puntatore } curr = 0; compute_center_of_mass(&(*root)); for (i = low; i < up; i++) { compute_force(&(*root), &(*bodies[i]), diameter, step); } // for (i = 0; i < nbodies; i++) { // } deallocate_tree(root); local_leafs = &leafs[low]; //inserire all_gather MPI_Allgather(local_leafs, up - low, bodytype, leafs, up - low, bodytype, comm); for (i = 0; i < nbodies; i++) { advance(&(*bodies[i])); } // int p = 0; // for (p = 0; p < nbodies; p++) // printf("%lf, %lf, %lf \n", bodies[p]->pos[0], bodies[p]->pos[1], // bodies[p]->pos[2]); // printf("*************************************** \n"); } // clockEnd = PAPI_get_real_usec(); // PAPI_stop(event_set, values); // int i = 0; // MPI_Send(bodies[low], up - low + 1, bodytype, 0, MPI_ANY_TAG, comm); } MPI_Finalize(); return 0; }
void DialupProperties::setApn(const QString &apn) { insert(APN_TAG, apn); }