Skip to content
Snippets Groups Projects
Commit b2ef03b0 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Automatic compilation

I modified the "LOAD" command in such a way that if one
writes "LOAD pippo.cpp" in the plumed.dat file, pippo.cpp is automatically
compiled to a pippo.so which is then loaded.
parent 21c43f76
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,7 @@
#include "ActionRegister.h"
using namespace PLMD;
using namespace std;
// !!!!!!!!!!!!!!!!!!!!!! DANGER !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11
// THE FOLLOWING ARE UTILITIES WHICH ARE NECESSARY FOR DYNAMIC LOADING OF THE PLUMED KERNEL:
......@@ -307,29 +308,8 @@ void PlumedMain::readInputFile(std::string str){
while(Tools::getParsedLine(fp,words)){
if(words.size()==0)continue;
else if(words[0]=="ENDPLUMED") break;
else if(words[0]=="LOAD"){
std::string s=words[1];
assert(words.size()==2);
void *p=plumed_dlopen(s.c_str());
if(!p){
// try with different extension
size_t n=s.find_last_of(".");
if(n==std::string::npos) s+=".";
else s=s.substr(0,n+1);
s+=soext;
p=plumed_dlopen(s.c_str());
}
if(!p){
log<<"ERROR\n";
log<<"I cannot load library "<<words[1].c_str()<<"\n";
log<<plumed_dlerror();
log<<"\n";
this->exit(1);
}
log<<"Loading shared library "<<s.c_str()<<"\n";
log<<"Here is the new list of available actions\n";
log<<actionRegister();
} else if(words[0]=="INCLUDE"){
else if(words[0]=="LOAD") load(words);
else if(words[0]=="INCLUDE"){
assert(words.size()==2);
readInputFile(words[1]);
continue;
......@@ -456,6 +436,37 @@ void PlumedMain::performCalc(){
for(ActionSet::iterator p=actionSet.begin();p!=actionSet.end();p++) (*p)->deactivate();
}
void PlumedMain::load(std::vector<std::string> & words){
string s=words[1];
assert(words.size()==2);
size_t n=s.find_last_of(".");
string extension="";
string base=s;
if(n!=std::string::npos && n<s.length()-1) extension=s.substr(n+1);
if(n!=std::string::npos && n<s.length()) base=s.substr(0,n);
if(extension=="cpp"){
string cmd="plumed mklib "+s;
log<<"Executing: "<<cmd;
if(comm.Get_size()>0) log<<" (only on master node)";
log<<"\n";
if(comm.Get_rank()==0) system(cmd.c_str());
comm.Barrier();
base="./"+base;
}
s=base+"."+soext;
void *p=plumed_dlopen(s.c_str());
if(!p){
log<<"ERROR\n";
log<<"I cannot load library "<<words[1].c_str()<<"\n";
log<<plumed_dlerror();
log<<"\n";
this->exit(1);
}
log<<"Loading shared library "<<s.c_str()<<"\n";
log<<"Here is the new list of available actions\n";
log<<actionRegister();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
......@@ -117,6 +117,8 @@ public:
const int & getStep()const{return step;};
/// Stop the run
void exit(int c=0);
/// Load a shared library
void load(std::vector<std::string> & words);
};
/////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment