Created
February 22, 2025 01:31
-
-
Save sjhalayka/43575da24e0661749e63e0f73d10c234 to your computer and use it in GitHub Desktop.
pointer usage with vector<vector<type>> etc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int read_data_fly(char* datafile, int dtype, double* data, float** probs, | |
| int num_samples_use, int* keepsamps, int start, int end, | |
| int* keeppreds_use, gzFile inputgz, size_t current, | |
| int num_samples, int num_preds, int genskip, int genheaders, | |
| int genprobs, size_t* bgen_indexes, double missingvalue, | |
| double threshold, double minprob, int nonsnp, | |
| int maxthreads) | |
| { | |
| int thread; | |
| int threadstart; | |
| int threadend; | |
| int threadlength; | |
| float*** threadprobs; | |
| vector<vector<vector<float>>> threadprobs_; | |
| // this is only temporary | |
| dtype = 2; | |
| maxthreads = 1; | |
| probs = malloc(sizeof(float*) * 2); | |
| probs[0] = malloc(sizeof(float) * num_samples_use * 1000); | |
| probs[1] = malloc(sizeof(float) * num_samples_use * 1000); | |
| if (dtype == 1 || dtype == 2 || dtype == 3 || | |
| dtype == 4) // can read in parallel | |
| { | |
| threadlength = (end - start - 1) / maxthreads + 1; | |
| if (dtype == 2) | |
| { | |
| threadprobs_.resize(maxthreads); | |
| cout << "Resized" << endl; | |
| //threadprobs = malloc(sizeof(float**) * maxthreads); | |
| } | |
| #pragma omp parallel for private(thread, threadstart, threadend) schedule(static, 1) | |
| for (thread = 0; thread < maxthreads; thread++) { | |
| ; | |
| threadstart = start + thread * threadlength; | |
| threadend = start + (thread + 1) * threadlength; | |
| if (threadend > end) { | |
| threadend = end; | |
| } | |
| if (dtype == 1) { | |
| read_bed_fly( | |
| datafile, data + (size_t)(threadstart - start) * num_samples_use, | |
| num_samples_use, keepsamps, threadend - threadstart, | |
| keeppreds_use + threadstart, num_samples, num_preds, missingvalue); | |
| } | |
| if (dtype == 2) { | |
| //if (probs == NULL) { | |
| // read_bgen_fly(datafile, | |
| // data + (size_t)(threadstart - start) * num_samples_use, | |
| // NULL, num_samples_use, keepsamps, threadstart, | |
| // threadend, keeppreds_use, num_samples, num_preds, | |
| // bgen_indexes, missingvalue, threshold, minprob); | |
| //} | |
| /*else*/ { | |
| //threadprobs_[thread] = malloc(sizeof(float*) * 2); | |
| threadprobs_[thread].resize(2); | |
| for (size_t i = 0; i < threadprobs_.size(); i++) | |
| for (size_t j = 0; j < threadprobs_[i].size(); j++) | |
| threadprobs_[i][j].resize(1); | |
| // for(size_t j = 0;) | |
| cout << "ptr usage ahead" << endl; | |
| //threadprobs[thread][0] = probs[0] + (size_t)(threadstart - start) * num_samples_use; | |
| //threadprobs[thread][1] = probs[1] + (size_t)(threadstart - start) * num_samples_use; | |
| ((float**)&threadprobs_[thread][0])[0] = probs[0] + (size_t)(threadstart - start) * num_samples_use; | |
| ((float**)&threadprobs_[thread][1])[0] = probs[1] + (size_t)(threadstart - start) * num_samples_use; | |
| cout << "ptr usage done" << endl; | |
| //read_bgen_fly( | |
| // datafile, data + (size_t)(threadstart - start) * num_samples_use, | |
| // ptr.get(), num_samples_use, keepsamps, threadstart, | |
| // threadend, keeppreds_use, num_samples, num_preds, bgen_indexes, | |
| // missingvalue, threshold, minprob); | |
| // threadprobs_[thread][0] = probs[0] + (size_t)(threadstart - start) * num_samples_use; | |
| // threadprobs_[thread][1] = probs[1] + (size_t)(threadstart - start) * num_samples_use; | |
| ///* ptr[0] = probs[0] + (size_t)(threadstart - start) * num_samples_use; | |
| // ptr[1] = probs[1] + (size_t)(threadstart - start) * num_samples_use;*/ | |
| // //threadprobs[thread][0] = probs[0] + (size_t)(threadstart - start) * num_samples_use; | |
| // //threadprobs[thread][1] = probs[1] + (size_t)(threadstart - start) * num_samples_use; | |
| // | |
| // read_bgen_fly( | |
| // datafile, data + (size_t)(threadstart - start) * num_samples_use, | |
| // threadprobs_[thread], num_samples_use, keepsamps, threadstart, | |
| // threadend, keeppreds_use, num_samples, num_preds, bgen_indexes, | |
| // missingvalue, threshold, minprob); | |
| // | |
| //free(threadprobs[thread]); | |
| } | |
| } | |
| if (dtype == 3) { | |
| read_sped_fly( | |
| datafile, data + (size_t)(threadstart - start) * num_samples_use, | |
| num_samples_use, keepsamps, threadstart, threadend, keeppreds_use, | |
| num_samples, num_preds, missingvalue, threshold, nonsnp); | |
| } | |
| if (dtype == 4) { | |
| read_speed_fly( | |
| datafile, data + (size_t)(threadstart - start) * num_samples_use, | |
| num_samples_use, keepsamps, threadstart, threadend, keeppreds_use, | |
| num_samples, num_preds, missingvalue, threshold, nonsnp); | |
| } | |
| } | |
| if (dtype == 2) { | |
| //free(threadprobs); | |
| } | |
| } | |
| if (dtype == 5) { | |
| (void)read_gen_fly(datafile, data, probs, num_samples_use, keepsamps, start, | |
| end, keeppreds_use, inputgz, current, num_samples, | |
| num_preds, genskip, genheaders, genprobs, missingvalue, | |
| threshold, minprob, nonsnp); | |
| } | |
| //free(probs[0]);// = malloc(sizeof(float) * num_samples_use * 1000); | |
| //free(probs[1]);// = malloc(sizeof(float) * num_samples_use * 1000); | |
| //free(probs);// = malloc(sizeof(float*) * 2); | |
| return (current + end); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment