Ejemplo n.º 1
0
TEST_F(MergeTests, DISABLED_parallel_heap_merger_delta_test) {
  TableGenerator g(true);
  hyrise::storage::atable_ptr_t main1 = g.int_random(1000, 1);
  hyrise::storage::atable_ptr_t main2 = g.int_random(1000, 1);
  hyrise::storage::atable_ptr_t delta = g.create_empty_table_modifiable(1000, 1);

  // copy main2 into delta
  delta->resize(main2->size());
  for (size_t i = 0; i < main2->size(); ++i) {
    hyrise_int_t v = main2->getValue<hyrise_int_t>(0, i);
    delta->setValue<hyrise_int_t>(0, i, v);
  }

  // delta and main2 should be equal
  ASSERT_TRUE(delta->contentEquals(main2));

  std::vector<hyrise::storage::c_atable_ptr_t > tables1;
  tables1.push_back(main1);
  tables1.push_back(main2);

  std::vector<hyrise::storage::c_atable_ptr_t> tables2;
  tables2.push_back(main1);
  tables2.push_back(delta);

  TableMerger merger1(new DefaultMergeStrategy(), new SequentialHeapMerger());
  const auto& result_1 = merger1.merge(tables1);

  TableMerger merger2(new DefaultMergeStrategy(), new SequentialHeapMerger());
  const auto& result_2 = merger2.merge(tables2);

  ASSERT_TRUE(result_1[0]->contentEquals(result_2[0]));

}
Ejemplo n.º 2
0
TEST_F(MergeTests, logarithmic_vs_simple_merge_test) {
  TableGenerator g(true);
  hyrise::storage::atable_ptr_t main = g.int_random(1000, 1);
  hyrise::storage::atable_ptr_t delta = g.int_random_delta(1000, 1);

  std::vector<hyrise::storage::c_atable_ptr_t > tables;
  tables.push_back(main);
  tables.push_back(delta);

  TableMerger merger1(new DefaultMergeStrategy(), new SequentialHeapMerger());
  const auto& result_simple = merger1.merge(tables);

  TableMerger merger2(new DefaultMergeStrategy(), new SequentialHeapMerger());
  const auto& result_heap = merger2.merge(tables);

  ASSERT_TRUE(result_simple[0]->contentEquals(result_heap[0]));
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    int k, i, **fd_p_s, j, mergenow, mergenext, ***mergfd, n, num_to_wait = 0, len, in, out, count, carry, gener = 1;
    char *s, key[3] = "0";
    FILE *f = fopen("psort.log", "w");
    freopen("out.txt", "w", stdout);
    fclose(f);
    setbuf(stdout, NULL);
    semid = semget(IPC_PRIVATE, 1, 0);
    semctl(semid, 0, SETVAL, (int)1);
    k = atoi(argv[1]);// number of processes
    if (argc == 3) // check if inputed key "-n"
        strncpy(key, argv[2], 2);
    mergfd = (int ***)malloc(1 * sizeof(int**)); //two arrays
    mergfd[0] = (int**)malloc(k * sizeof(int*));
    fd_p_s = (int**)malloc(k * sizeof(int*)); // fd from partitioner to sorter
    s = (char*)malloc(1* sizeof(char));
    for (i = 0; i < k; ++i) {
        fd_p_s[i] = (int*)malloc(2 * sizeof(int));
        mergfd[0][i] = (int*)malloc(2 * sizeof(int));
        pipe(fd_p_s[i]);
    }
    if (!fork())
        partitioner(fd_p_s, k);
    for (i = 0; i < k; ++i)
        close(fd_p_s[i][1]);
    for (i = 0; i < k; ++i){
        pipe(mergfd[0][i]);
        if (!fork())
            sorter(i, fd_p_s, k, key, mergfd[0][i][1]); //sort strings and sents it's part to mergfd[0][i][1]
    }
    num_to_wait = k + 1; //partitioner + k sorters
    for (i = 0; i < k; ++i)
        close(fd_p_s[i][0]);
    //start to merge in turn,
    mergenow = k;
    while (mergenow != 1){
        ++gener;
        mergenext = mergenow/2 + mergenow%2;
        mergfd = (int ***)realloc(mergfd, gener * sizeof(int**));
        mergfd[gener - 1] = (int**)malloc(mergenext * sizeof(int*));
        for (i = 0; i < mergenext; ++i){
            mergfd[gener - 1][i] = (int*)malloc(2 * sizeof(int));
            pipe(mergfd[gener - 1][i]);
        }
        count = 0;
        while (count < mergenow) {
            if (count + 1 == mergenow) { // not even number of mergers on this iteration; reached last one without pair
                if (!fork()){
                    merger1(mergfd[gener - 2][count][0], mergfd[gener - 1][count / 2][1], key, count/2, gener);
                    return 0;
                }
            }
            else {
                if (!fork()){
                    merger2(mergfd[gener - 2][count][0], mergfd[gener - 2][count + 1][0], mergfd[gener - 1][count / 2][1], key, count/2, gener);
                    return 0;
                }
            }
            count +=2;
            ++num_to_wait;
        }
        for(i = 0; i < mergenow; ++i)
            close(mergfd[gener - 2][i][0]);
        for(i = 0; i < mergenext; ++i)
            close(mergfd[gener - 1][i][1]);
        mergenow = mergenext;
    }
    my_read(mergfd[gener - 1][0][0], &n, sizeof(int));
    for (i = 0; i < n; ++i){
        my_read(mergfd[gener - 1][0][0], &len, sizeof(len));
        s = (char*)realloc(s, len * sizeof(char));
        my_read(mergfd[gener - 1][0][0], s, len);
        fputs(s, stdout);
        printf("\n");
    }
    for (i = 0; i < num_to_wait; ++i)
        wait(NULL);
    free(s);
    return 0;
}