void UmlRelation::write(FileOut & out, bool inside) { switch (relationKind()) { case aGeneralisation: if (inside) write_generalization(out); break; case aRealization: if (inside) parent()->memo_relation(this); else write_realization(out); break; case aDependency: if (inside) parent()->memo_relation(this); else write_dependency(out); break; default: // don't generate them for actors { UmlItem * p = parent(); if (p->stereotype() == "actor") return; do { p = p->parent(); } while (p->kind() == aClass); UmlItem * op = roleType(); if (op->stereotype() == "actor") return; do { op = op->parent(); } while (op->kind() == aClass); if ((p->kind() == aClassView) && (op->kind() == aClassView)) { if (inside) write_relation_as_attribute(out); else // note : it is the first side write_relation(out); } } break; } }
int create_relation_pk(relation_t *relation, int64_t num_tuples) { check_seed(); relation->num_tuples = num_tuples; if (!relation->tuples) { perror("memory must be allocated first"); return -1; } random_unique_gen(relation); #ifdef PERSIST_RELATIONS write_relation(relation, "R.tbl"); #endif return 0; }
int create_relation_fk(relation_t *relation, int64_t num_tuples, const int64_t maxid) { int32_t i, iters; int64_t remainder; relation_t tmp; check_seed(); relation->num_tuples = num_tuples; if (!relation->tuples) { perror("memory must be allocated first"); return -1; } /* alternative generation method */ iters = num_tuples / maxid; for(i = 0; i < iters; i++){ tmp.num_tuples = maxid; tmp.tuples = relation->tuples + maxid * i; random_unique_gen(&tmp); } /* if num_tuples is not an exact multiple of maxid */ remainder = num_tuples % maxid; if(remainder > 0) { tmp.num_tuples = remainder; tmp.tuples = relation->tuples + maxid * iters; random_unique_gen(&tmp); } #ifdef PERSIST_RELATIONS write_relation(relation, "S.tbl"); #endif return 0; }
int parallel_create_relation(relation_t *relation, uint64_t num_tuples, uint32_t nthreads, uint64_t maxid) { int rv; uint32_t i; uint64_t offset = 0; check_seed(); relation->num_tuples = num_tuples; if (!relation->tuples) { perror("memory must be allocated first"); return -1; } create_arg_t args[nthreads]; pthread_t tid[nthreads]; cpu_set_t set; pthread_attr_t attr; pthread_barrier_t barrier; unsigned int pagesize; unsigned int npages; unsigned int npages_perthr; uint64_t ntuples_perthr; uint64_t ntuples_lastthr; pagesize = getpagesize(); npages = (num_tuples * sizeof(tuple_t)) / pagesize + 1; npages_perthr = npages / nthreads; ntuples_perthr = npages_perthr * (pagesize/sizeof(tuple_t)); if(npages_perthr == 0) ntuples_perthr = num_tuples / nthreads; ntuples_lastthr = num_tuples - ntuples_perthr * (nthreads-1); pthread_attr_init(&attr); rv = pthread_barrier_init(&barrier, NULL, nthreads); if(rv != 0){ printf("[ERROR] Couldn't create the barrier\n"); exit(EXIT_FAILURE); } volatile void * locks = (volatile void *)calloc(num_tuples, sizeof(char)); for( i = 0; i < nthreads; i++ ) { int cpu_idx = get_cpu_id(i); CPU_ZERO(&set); CPU_SET(cpu_idx, &set); pthread_attr_setaffinity_np(&attr, sizeof(cpu_set_t), &set); args[i].firstkey = (offset + 1) % maxid; args[i].maxid = maxid; args[i].rel.tuples = relation->tuples + offset; args[i].rel.num_tuples = (i == nthreads-1) ? ntuples_lastthr : ntuples_perthr; args[i].fullrel = relation; args[i].locks = locks; args[i].barrier = &barrier; offset += ntuples_perthr; rv = pthread_create(&tid[i], &attr, random_unique_gen_thread, (void*)&args[i]); if (rv){ fprintf(stderr, "[ERROR] pthread_create() return code is %d\n", rv); exit(-1); } } for(i = 0; i < nthreads; i++){ pthread_join(tid[i], NULL); } /* randomly shuffle elements */ /* knuth_shuffle(relation); */ /* clean up */ free((char*)locks); pthread_barrier_destroy(&barrier); #ifdef PERSIST_RELATIONS char * const tables[] = {"R.tbl", "S.tbl"}; static int rs = 0; write_relation(relation, tables[(rs++)%2]); #endif return 0; }
S_LOCAL void s_write_utt_textgrid(const SUtterance *utt, SDatasource *ds, s_erc *error) { const SRelation *phraseRelation = NULL; const SRelation *wordRelation = NULL; const SRelation *syllableRelation = NULL; const SRelation *segmentRelation = NULL; int num_tiers = 0; int size = 0; s_bool is_present; const SItem *tmp; float end_time = 0.0; S_CLR_ERR(error); /* get relations, Phrase */ is_present = SUtteranceRelationIsPresent(utt, "Phrase", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit; if (is_present) { phraseRelation = SUtteranceGetRelation(utt, "Phrase", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceGetRelation\" failed")) goto quit; size += 1; } /* get relations, Word */ is_present = SUtteranceRelationIsPresent(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit; if (is_present) { wordRelation = SUtteranceGetRelation(utt, "Word", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceGetRelation\" failed")) goto quit; size += 1; } /* get relations, Syllable */ is_present = SUtteranceRelationIsPresent(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit; if (is_present) { syllableRelation = SUtteranceGetRelation(utt, "Syllable", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceGetRelation\" failed")) goto quit; size += 1; } /* get relations, Segment */ is_present = SUtteranceRelationIsPresent(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceRelationIsPresent\" failed")) goto quit; if (!is_present) { /* require at least segment relation */ S_CTX_ERR(error, S_FAILURE, "s_write_utt_textgrid", "Failed to find 'Segment' relation in utterance"); goto quit; } else { segmentRelation = SUtteranceGetRelation(utt, "Segment", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SUtteranceGetRelation\" failed")) goto quit; size += 1; } tmp = SRelationTail(segmentRelation, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SRelationTail\" failed")) goto quit; end_time = SItemGetFloat(tmp, "end", error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"SItemGetFloat\" failed")) goto quit; /* write textgrid header */ textgrid_header(ds, end_time, size, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"textgrid_header\" failed")) goto quit; num_tiers = write_relation(ds, phraseRelation, num_tiers, end_time, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"write_relation\" failed")) goto quit; num_tiers = write_relation(ds, wordRelation, num_tiers, end_time, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"write_relation\" failed")) goto quit; num_tiers = write_relation(ds, syllableRelation, num_tiers, end_time, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"write_relation\" failed")) goto quit; num_tiers = write_relation(ds, segmentRelation, num_tiers, end_time, error); if (S_CHK_ERR(error, S_CONTERR, "s_write_utt_textgrid", "Call to \"write_relation\" failed")) goto quit; /* cleanup */ quit: if (ds != NULL) S_DELETE(ds, "s_write_utt_textgrid", error); }