int main(int argc, char **argv) { int ret; int provided = 0; struct mdhim_t *md; uint32_t key, **secondary_keys; int value, *secondary_key_lens; struct mdhim_brm_t *brm; struct mdhim_bgetrm_t *bgrm; mdhim_options_t *db_opts; struct index_t *secondary_index; struct secondary_info *secondary_info; MPI_Comm comm; ret = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); if (ret != MPI_SUCCESS) { printf("Error initializing MPI with threads\n"); exit(1); } if (provided != MPI_THREAD_MULTIPLE) { printf("Not able to enable MPI_THREAD_MULTIPLE mode\n"); exit(1); } db_opts = mdhim_options_init(); mdhim_options_set_db_path(db_opts, "./"); mdhim_options_set_db_name(db_opts, "mdhimTstDB"); mdhim_options_set_db_type(db_opts, LEVELDB); mdhim_options_set_key_type(db_opts, MDHIM_INT_KEY); //Key_type = 1 (int) mdhim_options_set_debug_level(db_opts, MLOG_CRIT); comm = MPI_COMM_WORLD; md = mdhimInit(&comm, db_opts); if (!md) { printf("Error initializing MDHIM\n"); exit(1); } //Put the primary keys and secondary keys key = 100 * (md->mdhim_rank + 1); value = 500 * (md->mdhim_rank + 1); secondary_keys = malloc(sizeof(uint32_t *)); secondary_keys[0] = malloc(sizeof(uint32_t)); *secondary_keys[0] = md->mdhim_rank + 1; secondary_key_lens = malloc(sizeof(int)); secondary_key_lens[0] = sizeof(uint32_t); //Create a secondary index secondary_index = create_global_index(md, 2, SECONDARY_SLICE_SIZE, LEVELDB, MDHIM_INT_KEY); secondary_info = mdhimCreateSecondaryInfo(secondary_index, (void **) secondary_keys, secondary_key_lens, 1, SECONDARY_GLOBAL_INFO); brm = mdhimPut(md, &key, sizeof(key), &value, sizeof(value), secondary_info, NULL); if (!brm || brm->error) { printf("Error inserting key/value into MDHIM\n"); } else { printf("Successfully inserted key/value into MDHIM\n"); } //Release the received message mdhim_full_release_msg(brm); //Commit the database ret = mdhimCommit(md, md->primary_index); if (ret != MDHIM_SUCCESS) { printf("Error committing MDHIM database\n"); } else { printf("Committed MDHIM database\n"); } brm = mdhimDelete(md, secondary_index, secondary_keys[0], secondary_key_lens[0]); if (!brm || brm->error) { printf("Error deleting key/value from MDHIM\n"); } else { printf("Successfully deleted key/value into MDHIM\n"); } //Get the primary key values from the secondary key - this should fail value = 0; bgrm = mdhimGet(md, secondary_index, secondary_keys[0], secondary_key_lens[0], MDHIM_GET_PRIMARY_EQ); if (!bgrm || bgrm->error) { printf("Error getting value for key: %d from MDHIM\n", key); } else if (bgrm->value_lens[0]) { printf("Successfully got value: %d from MDHIM\n", *((int *) bgrm->values[0])); } mdhim_full_release_msg(bgrm); free(secondary_keys[0]); free(secondary_keys); free(secondary_key_lens); ret = mdhimClose(md); mdhim_options_destroy(db_opts); if (ret != MDHIM_SUCCESS) { printf("Error closing MDHIM\n"); } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { int ret; int provided = 0; struct mdhim_t *md; int key; int value; struct mdhim_rm_t *rm; struct mdhim_getrm_t *grm; char *db_path = "./"; char *db_name = "mdhimTstDB-"; int dbug = MLOG_DBG; db_options_t *db_opts; // Local variable for db create options to be passed int db_type = 2; //UNQLITE=1, LEVELDB=2 (data_store.h) // Create options for DB initialization db_opts = db_options_init(); db_options_set_path(db_opts, db_path); db_options_set_name(db_opts, db_name); db_options_set_type(db_opts, db_type); db_options_set_key_type(db_opts, MDHIM_INT_KEY); db_options_set_debug_level(db_opts, dbug); ret = MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided); if (ret != MPI_SUCCESS) { printf("Error initializing MPI with threads\n"); exit(1); } if (provided != MPI_THREAD_MULTIPLE) { printf("Not able to enable MPI_THREAD_MULTIPLE mode\n"); exit(1); } md = mdhimInit(MPI_COMM_WORLD, db_opts); if (!md) { printf("Error initializing MDHIM\n"); exit(1); } //Put the keys and values key = 20 * (md->mdhim_rank + 1); value = 1000 * (md->mdhim_rank + 1); rm = mdhimPut(md, &key, sizeof(key), &value, sizeof(value)); if (!rm || rm->error) { printf("Error inserting key/value into MDHIM\n"); } else { printf("Successfully inserted key/value into MDHIM\n"); } rm = mdhimDelete(md, &key, sizeof(key)); if (!rm || rm->error) { printf("Error deleting key/value from MDHIM\n"); } else { printf("Successfully deleted key/value into MDHIM\n"); } //Get the values value = 0; grm = mdhimGet(md, &key, sizeof(key), MDHIM_GET_EQ); if (!grm || grm->error) { printf("Error getting value for key: %d from MDHIM\n", key); } else if (grm->value_len) { printf("Successfully got value: %d from MDHIM\n", *((int *) grm->value)); } ret = mdhimClose(md); if (ret != MDHIM_SUCCESS) { printf("Error closing MDHIM\n"); } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; }