Skip to content
Snippets Groups Projects
Select Git revision
  • d80fecc4df2d4ee019aa05cbcf576b252fc7f19e
  • master default
  • releases/2.10
  • feature/update-buildsystem
  • releases/2.9
  • more-features-for-cholmodsolver
  • releases/2.8
  • fix/error-norm
  • releases/2.7
  • implement-overlappingblockgsstep
  • make-getiterationstep-return-shared-ptr
  • feature/blockgssteps_autoCopy
  • releases/2.6-1
  • feature/use-smart-ptr-ignorenodes
  • feature/update-to-clang-7
  • feature/whitespace-fix
  • flexible-loopsolver-max
  • releases/2.5-1
  • feature/incomplete-cholesky-rebased
  • feature/istl-preconditioners
  • feature/optional-ignore
  • subversion->git
22 results

projectedblockgsstep.cc

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    trex.cpp 2.28 KiB
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <sstream>
    #include <cpputils/cpputils.h>
    #include <misc/GlobalSettings.h>
    #include <misc/create_struct.h>
    
    #if WIN32
    #define OS_SEP '\\'
    #else
    #define OS_SEP '/'
    #endif
    
    std::string conda_environment_path(const char* argv) {
    #ifdef TREX_PYTHON_PATH
        auto compiled_path = file::Path(TREX_PYTHON_PATH).is_regular() ? file::Path(TREX_PYTHON_PATH).remove_filename().str() : file::Path(TREX_PYTHON_PATH).str();
    #else
        std::string compiled_path = "";
    #endif
        
    #ifdef TREX_CONDA_PACKAGE_INSTALL
        return compiled_path;
    #else
        auto conda_prefix = getenv("CONDA_PREFIX");
        std::string envs = "envs";
        envs += OS_SEP;
        
        std::string home = compiled_path;
        if(conda_prefix) {
            // we are inside a conda environment
            home = conda_prefix;
        } else if(utils::contains(argv, envs)) {
            auto folders = utils::split(argv, OS_SEP);
            std::string previous = "";
            home = "";
            
            for(auto &folder : folders) {
                home += folder;
                
                if(previous == "envs") {
                    break;
                }
                
                home += OS_SEP;
                previous = folder;
            }
        }
        return home;
    #endif
    }
    
    int main(int argc, char** argv) {
        std::stringstream ss;
        std::string target_path = "";
        auto conda_prefix = conda_environment_path(argv[0]);
        if(!conda_prefix.empty()) {
            target_path = conda_prefix;
            target_path += "/bin/";
            
            printf("Using conda prefix '%s'.\n", target_path.c_str());
        } else {
            target_path = argv[0];
            for(long i=(long)target_path.size(); i>0; --i) {
                if (target_path[i] == '/' || target_path[i] == '\\') {
                    target_path = target_path.substr(0, i);
                    break;
                }
            }
            target_path += "/";
            printf("Using argv[0] = '%s'...\n", target_path.c_str());
        }
        
    #if __APPLE__
        ss << "";
    #endif
        ss << target_path;
    #if __APPLE__
        ss << "TRex.app/Contents/MacOS/TRex";
    #else
        U_EXCEPTION("Only apple supported.");
    #endif
    
        for(auto i=1; i<argc; ++i)
            ss << " " << argv[i];
        
        auto str = ss.str();
        printf("Calling '%s'...\n", str.c_str());
        fflush(stdout);
        system(str.c_str());
        
        return 0;
    }