// we can initialize MPI exactly once, so everything is clubbed into this test
TEST(MpiEnvTest, ExceptionsNoAbort) {
    int argc=1;
    char arg0[]="";
    char* args[]={arg0};
    char** argv=args;

    ASSERT_EQ(0, get_mpi_abort_called()) << "Unexpected initial global counter state";
    ASSERT_FALSE(mpi_is_up());

    try {
      alps::mpi::environment env(argc, argv, false);
        ASSERT_TRUE(mpi_is_up());

        try {
            alps::mpi::environment sub_env(argc, argv);
            throw std::exception();
        } catch (std::exception&) {
            ASSERT_FALSE(mpi_is_down());
            ASSERT_EQ(0, get_mpi_abort_called()) << "MPI_Abort should not be called";
            throw;
        }
    } catch (std::exception&) {
        // MPI env object is destroyed during active exception,
        // should not have called abort (but finalize MPI)
        ASSERT_EQ(0, get_mpi_abort_called()) << "MPI_Abort should not be called";
        ASSERT_TRUE(mpi_is_down());
    }
}
Exemplo n.º 2
0
// we can initialize MPI exactly once, so everything is clubbed into this test
TEST(MpiEnvTest, Environment) {
    int argc=1;
    char arg0[]="";
    char* args[]={arg0};
    char** argv=args;
    ASSERT_FALSE(mpi_is_up());
    ASSERT_FALSE(mpi_is_down());
    ASSERT_FALSE(alps::mpi::environment::initialized()) << "MPI Env should not be initialized";
    ASSERT_FALSE(alps::mpi::environment::finalized()) << "MPI Env should not be finalized";
    {
        alps::mpi::environment env(argc, argv);
        ASSERT_TRUE(mpi_is_up());
        ASSERT_FALSE(mpi_is_down());

        ASSERT_TRUE(alps::mpi::environment::initialized()) << "MPI Env should be initialized by now";
        ASSERT_FALSE(alps::mpi::environment::finalized()) << "MPI Env should not be finalized yet";

        {
            alps::mpi::environment sub_env(argc, argv);
            ASSERT_TRUE(mpi_is_up());
            ASSERT_FALSE(mpi_is_down());
        } // sub_env destroyed
        ASSERT_TRUE(mpi_is_up()) << "MPI should remain initialized after sub-object destruction";
        ASSERT_FALSE(mpi_is_down()) << "MPI should not be finalized after sub-object destruction";
    } // env destroyed

    ASSERT_TRUE(mpi_is_up());
    ASSERT_TRUE(mpi_is_down()) << "MPI should be finalized after environment destruction";

    ASSERT_TRUE(alps::mpi::environment::initialized()) << "MPI Env should be initialized after environment destruction";
    ASSERT_TRUE(alps::mpi::environment::finalized()) << "MPI Env should be finalized after environment destruction";
}
Exemplo n.º 3
0
char *eval_prompt(char *prompt) {
    sub_env(prompt);
    // Flag to indicate inside {...} block
    int in_macro = 0;
    // Counters to track lengths
    int prompt_len = strlen(prompt);
    // Buffers
    char macro[prompt_len];
    *macro -= *macro;
    char *new_prompt = calloc(1, 128);
    *new_prompt -= *new_prompt;
    int i = 0;
    while (i < prompt_len) {
        if (prompt[i] == '\\' && prompt[i - 1] != '\\') {
            i++;
            continue;
        }   
        if (prompt[i] == '{' && prompt[i - 1] != '\\') {
            in_macro = 1;
        } else if (prompt[i] == '}' && prompt[i - 1] != '\\') {
            if (in_macro) {
                in_macro = 0;
                eval_macro(macro, new_prompt);
                strcpy(macro, "");
            } else {
                strncat(new_prompt, &prompt[i], 1);
            }
        } else {
            if (in_macro) {
                strncat(macro, &prompt[i], 1);
            } else {
                strncat(new_prompt, &prompt[i], 1);
            }
        }
        i++;
    }
    if (in_macro && strlen(macro)) {
        eval_macro(macro, new_prompt);
    }
    char *copy = calloc(1, strlen(new_prompt) + 1);
    strcpy(copy, new_prompt);
    free(new_prompt);
    return copy;
}