Trisurf Monte Carlo simulator
Samo Penic
2019-02-28 ca9f26089df29fec5995ed4f19a06c29f7f4b12e
Plugin chains to speed up running of plugins, part 1.
6 files modified
79 ■■■■ changed files
src/general.h 14 ●●●●● patch | view | raw | blame | history
src/main.c 26 ●●●● patch | view | raw | blame | history
src/plugins.c 34 ●●●●● patch | view | raw | blame | history
src/plugins.h 1 ●●●● patch | view | raw | blame | history
src/tape 2 ●●● patch | view | raw | blame | history
src/vesicle.c 2 ●●●●● patch | view | raw | blame | history
src/general.h
@@ -331,9 +331,23 @@
    void *libhandle;
} ts_plugin;
struct ts_plugin_chain {
    ts_plugin *plugin;
    struct ts_plugin_chain *next;
};
typedef struct ts_plugin_chain ts_plugin_chain;
typedef struct {
    ts_plugin_chain *at_start;
    ts_plugin_chain *after_vesicle_init;
    ts_plugin_chain *cleanup;
} ts_plugin_chains;
typedef struct {
    ts_uint n;
    ts_plugin **plugin;
    ts_plugin_chains *chain;
} ts_plugin_list;
/* end plugins */
src/main.c
@@ -34,7 +34,8 @@
    *plugins=plugin0;
    plugins[1]=plugin1;
    ts_plugin_list *plist=init_plugin_list(plugins,2);
    ts_fprintf(stdout, "TRISURF in PRVI PLUGIN %s\n", plist->plugin[0]->details->name);
    //printf("%s", plist->chain->at_start->next->plugin->filename);
    //ts_fprintf(stdout, "TRISURF in PRVI PLUGIN %s\n", plist->plugin[0]->details->name);
    ts_vesicle *vesicle;
    ts_tape *tape;
    ts_uint start_iteration=0;
@@ -51,9 +52,10 @@
    ts_fprintf(stdout,"Starting program...\n\n");
    
/* Entry point for plugin function at_start() */
    int i;
    for(i=0; i<plist->n; i++){
        plist->plugin[i]->function->at_start(argv, argc);
    ts_plugin_chain *ptr=plist->chain->at_start;
    while(ptr!=NULL){
        ptr->plugin->function->at_start(argv,argc);
        ptr=ptr->next;
    }
    if(command_line_args.dump_from_vtk[0]!=0){
@@ -138,13 +140,23 @@
    vesicle->plist=plist;
/* Entry point for plugin after_vesicle_init() function */
    for(i=0; i<plist->n; i++){
        vesicle = plist->plugin[i]->function->after_vesicle_init(vesicle);
    ptr=plist->chain->after_vesicle_init;
    while(ptr!=NULL){
        ptr->plugin->function->after_vesicle_init(vesicle);
        ptr=ptr->next;
    }
    run_simulation(vesicle, tape->mcsweeps, tape->inititer, tape->iterations, start_iteration);
    write_master_xml_file(command_line_args.output_fullfilename);
    write_dout_fcompat_file(vesicle,"dout");
/* Entry point for plugin cleanup() function */
    ptr=plist->chain->cleanup;
    while(ptr!=NULL){
        ptr->plugin->function->cleanup();
        ptr=ptr->next;
    }
    vesicle_free(vesicle);
    tape_free(tape);
    return 0; //program finished perfectly ok. We return 0.
src/plugins.c
@@ -103,6 +103,10 @@
        fatal("Exiting",235);
    }
    ts_plugin_details* (*get_plugin_details)(void) = dlsym(plugin->libhandle, "init");
    if(get_plugin_details==NULL){
        ts_fprintf(stderr,"Plugin %s invalid. No init() function.\n", filename);
        fatal("Exiting", 235);
    }
    plugin->details = get_plugin_details();
    plugin->function = (ts_plugin_function *)calloc(1,sizeof(ts_plugin_function));
    
@@ -121,12 +125,39 @@
}
ts_plugin_chain *plugin_to_chain(ts_plugin_chain *chain, ts_plugin *plugin){
    ts_plugin_chain *retchain;
    if(chain!=NULL){
        retchain=chain;
        while(chain->next!=NULL){
            chain=chain->next;
        }
        chain->next=(ts_plugin_chain *)calloc(1,sizeof(ts_plugin_chain));
        chain->next->plugin=plugin;
        return retchain;
    } else {
        chain=(ts_plugin_chain *)calloc(1,sizeof(ts_plugin_chain));
        chain->plugin=plugin;
        return chain;
    }
}
ts_plugin_list *init_plugin_list(ts_char **plugin_filenames, ts_uint number_of_plugins){
    ts_plugin_list *plist=(ts_plugin_list *)calloc(1, sizeof(ts_plugin_list));
    plist->plugin=(ts_plugin **)calloc(number_of_plugins, sizeof(ts_plugin *));
    plist->chain=(ts_plugin_chains *)calloc(1, sizeof(ts_plugin_chains));
    for(int i=0;i<number_of_plugins;i++){
        plist->plugin[i]=init_plugin(plugin_filenames[i]);
        if(plist->plugin[i]->function->cleanup!=NULL){
            plist->chain->cleanup=plugin_to_chain(plist->chain->cleanup, plist->plugin[i]);
        }
        if(plist->plugin[i]->function->at_start!=NULL){
            plist->chain->at_start=plugin_to_chain(plist->chain->at_start, plist->plugin[i]);
        }
    }
    //printf("%s", plist->chain->at_start->next->plugin->filename);
    plist->n=number_of_plugins;
    return plist;
}    
@@ -140,9 +171,10 @@
    free(plugin);
}
void free_plugin_list(ts_plugin_list *plist){
void plugin_list_free(ts_plugin_list *plist){
    for(int i=0;i<plist->n;i++){
        free_plugin(plist->plugin[i]);
    }
    free(plist->chain);
    free(plist);
}
src/plugins.h
@@ -3,4 +3,5 @@
#include "general.h"
ts_plugin *init_plugin(ts_char *filename);
ts_plugin_list *init_plugin_list(ts_char **plugin_filenames, ts_uint number_of_filenames);
void plugin_list_free(ts_plugin_list *plist);
#endif
src/tape
@@ -14,7 +14,7 @@
# (pswitch=1: calc. p*dV energy contribution)
pswitch = 1
# pressure difference: p_inside - p_outside (in units kT/l_min^3):
pressure=-100.0
pressure=-10.0
#Constant volume constraint (0 disable constant volume, 1 enable wiht additional vertex move, 2 enable with epsvol)
constvolswitch=0
src/vesicle.c
@@ -9,6 +9,7 @@
#include "poly.h"
#include "sh.h"
#include "shcomplex.h"
#include "plugins.h"
ts_vesicle *init_vesicle(ts_uint N, ts_uint ncmax1, ts_uint ncmax2, ts_uint
ncmax3, ts_double stepsize){
@@ -40,6 +41,7 @@
    poly_list_free(vesicle->poly_list);
    poly_list_free(vesicle->filament_list);
    complex_sph_free(vesicle->sphHarmonics);
    plugin_list_free(vesicle->plist);
    free(vesicle);
    return TS_SUCCESS;
}