Skip to content

Commit

Permalink
next debug-print round
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchang committed May 22, 2024
1 parent fa16f9e commit 1245195
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
15 changes: 15 additions & 0 deletions 2.0/include/plink2_text.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,14 @@ THREAD_FUNC_DECL TextStreamThread(void* raw_arg) {

const char kShortErrRfileInvalid[] = "TextStreamOpenEx can't be called with a closed or error-state textFILE";

const char kDebugFail1[] = "TextStreamOpenEx fail 1";
const char kDebugFail2[] = "TextStreamOpenEx fail 2";
const char kDebugFail3[] = "TextStreamOpenEx fail 3";
const char kDebugFail4[] = "TextStreamOpenEx fail 4";
const char kDebugFail5[] = "TextStreamOpenEx fail 5";
const char kDebugFail6[] = "TextStreamOpenEx fail 6";
const char kDebugFail7[] = "TextStreamOpenEx fail 7";

PglErr TextStreamOpenEx(const char* fname, uint32_t enforced_max_line_blen, uint32_t dst_capacity, uint32_t decompress_thread_ct, textFILE* txf_ptr, char* dst, TextStream* txs_ptr) {
TextStreamMain* txsp = GetTxsp(txs_ptr);
TextFileBase* txs_basep = &txsp->base;
Expand Down Expand Up @@ -1382,6 +1390,7 @@ PglErr TextStreamOpenEx(const char* fname, uint32_t enforced_max_line_blen, uint
reterr = BgzfRawMtStreamInit(nullptr, decompress_thread_ct, txs_basep->ff, &txfp->rds.bgzf, &txsp->rds.bgzf, &txs_basep->errmsg);
if (unlikely(reterr)) {
EraseTextFileBase(&txfp->base);
txs_basep->errmsg = kDebugFail1;
goto TextStreamOpenEx_ret_1;
}
}
Expand All @@ -1395,11 +1404,13 @@ PglErr TextStreamOpenEx(const char* fname, uint32_t enforced_max_line_blen, uint
txs_basep->reterr = kPglRetEof;
return kPglRetSuccess;
}
txs_basep->errmsg = kDebugFail2;
goto TextStreamOpenEx_ret_1;
}
assert(!txsp->syncp);
TextStreamSync* syncp;
if (unlikely(cachealigned_malloc(RoundUpPow2(sizeof(TextStreamSync), kCacheline), &syncp))) {
txs_basep->errmsg = kDebugFail3;
goto TextStreamOpenEx_ret_NOMEM;
}
txsp->syncp = syncp;
Expand Down Expand Up @@ -1439,22 +1450,26 @@ PglErr TextStreamOpenEx(const char* fname, uint32_t enforced_max_line_blen, uint
#else
syncp->sync_init_state = 0;
if (unlikely(pthread_mutex_init(&syncp->sync_mutex, nullptr))) {
txs_basep->errmsg = kDebugFail4;
goto TextStreamOpenEx_ret_THREAD_CREATE_FAIL;
}
syncp->sync_init_state = 1;
if (unlikely(pthread_cond_init(&syncp->reader_progress_condvar, nullptr))) {
txs_basep->errmsg = kDebugFail5;
goto TextStreamOpenEx_ret_THREAD_CREATE_FAIL;
}
syncp->sync_init_state = 2;
syncp->consumer_progress_state = 0;
if (unlikely(pthread_cond_init(&syncp->consumer_progress_condvar, nullptr))) {
txs_basep->errmsg = kDebugFail6;
goto TextStreamOpenEx_ret_THREAD_CREATE_FAIL;
}
syncp->sync_init_state = 3;
# ifdef __cplusplus
if (unlikely(pthread_create(&syncp->read_thread,
&g_thread_startup.smallstack_thread_attr,
TextStreamThread, txsp))) {
txs_basep->errmsg = kDebugFail7;
goto TextStreamOpenEx_ret_THREAD_CREATE_FAIL;
}
# else
Expand Down
3 changes: 0 additions & 3 deletions 2.0/plink2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,6 @@ PglErr Plink2Core(const Plink2Cmdline* pcp, MakePlink2Flags make_plink2_flags, c
// --update-name in the order of operations.
const uint32_t htable_needed_early = variant_ct && (pcp->varid_from || pcp->varid_to || pcp->varid_snp || pcp->varid_exclude_snp || pcp->snps_range_list.name_ct || pcp->exclude_snps_range_list.name_ct);
const uint32_t full_variant_id_htable_needed = variant_ct && (htable_needed_early || pcp->update_map_flag || pcp->update_name_flag || pcp->update_alleles_fname || (pcp->rmdup_mode != kRmDup0) || pcp->extract_col_cond_info.params);
DPrintf("before ApplyVariantBpFilters()\n");
if (!full_variant_id_htable_needed) {
reterr = ApplyVariantBpFilters(pcp->extract_fnames, pcp->extract_intersect_fnames, pcp->exclude_fnames, cip, variant_bps, pcp->from_bp, pcp->to_bp, pcp->bed_border_bp, raw_variant_ct, pcp->filter_flags, vpos_sortstatus, pcp->max_thread_ct, variant_include, &variant_ct);
if (unlikely(reterr)) {
Expand Down Expand Up @@ -1413,7 +1412,6 @@ PglErr Plink2Core(const Plink2Cmdline* pcp, MakePlink2Flags make_plink2_flags, c
uint32_t* sample_missing_hc_cts = nullptr;
uint32_t* sample_hethap_cts = nullptr;
uintptr_t max_covar_name_blen = 0;
DPrintf("before psamname[0]\n");
if (psamname[0]) {
// xid_mode may vary between these operations in a single run, and
// sample-sort is relatively cheap, so we abandon plink 1.9's "construct
Expand Down Expand Up @@ -1442,7 +1440,6 @@ PglErr Plink2Core(const Plink2Cmdline* pcp, MakePlink2Flags make_plink2_flags, c
}
// --update-parents goes here
if (pcp->update_sex_info.fname) {
DPrintf("starting --update-sex on %s\n", pcp->update_sex_info.fname);
reterr = UpdateSampleSexes(sample_include, &pii.sii, &(pcp->update_sex_info), raw_sample_ct, sample_ct, pcp->max_thread_ct, sex_nm, sex_male);
if (unlikely(reterr)) {
goto Plink2Core_ret_1;
Expand Down
1 change: 1 addition & 0 deletions 2.0/plink2_decompress.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ HEADER_INLINE PglErr SizeAndInitTextStream(const char* fname, uintptr_t byte_ava
if (unlikely(StandardizeMaxLineBlen(byte_avail_ct, &max_line_blen))) {
return kPglRetNomem;
}
DPrintf("max_line_blen: %u\n", max_line_blen);
return InitTextStream(fname, max_line_blen, decompress_thread_ct, txsp);
}

Expand Down
14 changes: 7 additions & 7 deletions 2.0/plink2_misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2214,26 +2214,30 @@ PglErr UpdateSampleSexes(const uintptr_t* sample_include, const SampleIdInfo* si
if (!sample_ct) {
goto UpdateSampleSexes_ret_1;
}
DPrintf("before SizeAndInitTextStream()\n");
DPrintf("before SizeAndInitTextStream() bigstack_left() = %" PRIuPTR "\n", bigstack_left());
// permit very long lines since this can be pointed at .ped files
reterr = SizeAndInitTextStream(update_sex_info_ptr->fname, bigstack_left() - (bigstack_left() / 4), MAXV(max_thread_ct - 1, 1), &txs);
if (unlikely(reterr)) {
DPrintf("reterr: %u\n", S_CAST(uint32_t, reterr));
const char* errmsg = TextStreamError(&txs);
if (errmsg) {
DPrintf("errmsg: %s\n", errmsg);
}
goto UpdateSampleSexes_ret_1;
}
DPrintf("no SizeAndInitTextStream() error\n");

// (Much of this boilerplate is shared with e.g. KeepColMatch(); it
// probably belongs in its own function.)
char* line_start;
XidMode xid_mode;
DPrintf("before LoadXidHeader()\n");
reterr = LoadXidHeader("update-sex", (siip->sids || (siip->flags & kfSampleIdStrictSid0))? kfXidHeaderFixedWidth : kfXidHeaderFixedWidthIgnoreSid, &line_idx, &txs, &xid_mode, &line_start);
if (reterr) {
if (likely(reterr == kPglRetEof)) {
reterr = kPglRetSuccess;
logputs("--update-sex: 0 samples updated.\n");
goto UpdateSampleSexes_ret_1;
}
DPrintf("TSTREAM_XID_FAIL\n");
goto UpdateSampleSexes_ret_TSTREAM_XID_FAIL;
}
const uint32_t id_col_ct = GetXidColCt(xid_mode);
Expand Down Expand Up @@ -2274,7 +2278,6 @@ PglErr UpdateSampleSexes(const uintptr_t* sample_include, const SampleIdInfo* si
char* sorted_xidbox = nullptr;
const uint32_t allow_dups = siip->sids && (!(xid_mode & kfXidModeFlagSid));
uintptr_t max_xid_blen;
DPrintf("before SortedXidboxInitAlloc()\n");
reterr = SortedXidboxInitAlloc(sample_include, siip, sample_ct, allow_dups, xid_mode, 0, &sorted_xidbox, &xid_map, &max_xid_blen);
if (unlikely(reterr)) {
goto UpdateSampleSexes_ret_1;
Expand All @@ -2298,7 +2301,6 @@ PglErr UpdateSampleSexes(const uintptr_t* sample_include, const SampleIdInfo* si
const char* linebuf_iter = line_start;
uint32_t xid_idx_start;
uint32_t xid_idx_end;
DPrintf("processing line %" PRIuPTR "\n", line_idx);
if (SortedXidboxReadMultifind(sorted_xidbox, max_xid_blen, sample_ct, 0, xid_mode, &linebuf_iter, &xid_idx_start, &xid_idx_end, idbuf)) {
if (unlikely(!linebuf_iter)) {
goto UpdateSampleSexes_ret_MISSING_TOKENS;
Expand Down Expand Up @@ -2368,11 +2370,9 @@ PglErr UpdateSampleSexes(const uintptr_t* sample_include, const SampleIdInfo* si
}
}
}
DPrintf("done with loop\n");
if (unlikely(TextStreamErrcode2(&txs, &reterr))) {
goto UpdateSampleSexes_ret_TSTREAM_FAIL;
}
DPrintf("no close error\n");
if (duplicate_ct) {
logprintfww("Note: %" PRIuPTR " duplicate sample ID%s) in --update-sex file.\n", duplicate_ct, (duplicate_ct == 1)? " (with a consistent sex assignment" : "s (with consistent sex assignments");
}
Expand Down

0 comments on commit 1245195

Please sign in to comment.