+ for (int i = 0; i < nSpC; i++) delete[] vecs[i];
+ delete[] vecs;
+
+ return NULL;
+}
+
+template<class ModelType>
+void sample_theta_vectors_from_count_vectors() {
+ ModelType model;
+ model.read(modelF);
+ calcExpectedEffectiveLengths<ModelType>(model);
+
+ buffer = new Buffer(nMB, nSamples, cvlen, tmpF);
+
+ paramsArray = new Params[nThreads];
+ threads = new pthread_t[nThreads];
+
+ char inpF[STRLEN];
+ for (int i = 0; i < nThreads; i++) {
+ paramsArray[i].no = i;
+ sprintf(inpF, "%s%d", cvsF, i);
+ paramsArray[i].fi = fopen(inpF, "r");
+ paramsArray[i].engine = engineFactory::new_engine();
+ paramsArray[i].mw = model.getMW();
+ }
+
+ /* set thread attribute to be joinable */
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+
+ for (int i = 0; i < nThreads; i++) {
+ rc = pthread_create(&threads[i], &attr, &sample_theta_from_c, (void*)(¶msArray[i]));
+ pthread_assert(rc, "pthread_create", "Cannot create thread " + itos(i) + " (numbered from 0) in sample_theta_vectors_from_count_vectors!");
+ }
+ for (int i = 0; i < nThreads; i++) {
+ rc = pthread_join(threads[i], &status);
+ pthread_assert(rc, "pthread_join", "Cannot join thread " + itos(i) + " (numbered from 0) in sample_theta_vectors_from_count_vectors!");
+ }
+
+ /* destroy attribute */
+ pthread_attr_destroy(&attr);
+ delete[] threads;
+
+ for (int i = 0; i < nThreads; i++) {
+ fclose(paramsArray[i].fi);
+ delete paramsArray[i].engine;
+ }
+ delete[] paramsArray;
+
+ delete buffer; // Must delete here, force the content left in the buffer be written into the disk
+