gs_sequence.c

Go to the documentation of this file.
00001 /********************************************************************/
00002 /*                           gs_sequence.c                          */
00003 /*        the source code for the GridSolve sequencing API          */
00004 /*                       Yinan Li, 05/17/2007                       */
00005 /********************************************************************/
00006 
00007 
00008 #include "gs_sequence.h"
00009 
00010 /* the global GridSolve sequence DAG */
00011 GS_DAG_t *GS_SEQ_DAG = NULL;
00012 
00013 
00014 /* the current sequencing mode, could be either
00015    OPTIMISTIC_MODE
00016    or
00017    RESTRICTIVE_MODE
00018    or
00019    CONSERVATIVE_MODE
00020    or
00021    OFF_MODE
00022    OFF_MODE can not be used as the initial mode
00023 */
00024 int grpc_sequence_mode;
00025 
00026 /* the sequencing language, could be either
00027    CALL_FROM_C
00028    or
00029    CALL_FROM_FORTRAN */
00030 int grpc_sequence_language;
00031 
00032 /* the sequencing major, could be either 'r' or 'c' */
00033 int grpc_sequence_major;
00034 
00035 
00036 
00042 void grpc_sequence_begin(int mode) {
00043     /* set the sequencing mode to what is specified */
00044     grpc_sequence_mode = mode;
00045     /* set the sequencing language to default */
00046     grpc_sequence_language = GS_CALL_FROM_C;
00047     /* set the sequencing major to what is specified */
00048     grpc_sequence_major = 'r';
00049 
00050     /* make a new empty DAG */
00051     GS_SEQ_DAG = make_new_GS_DAG();
00052     if (GS_SEQ_DAG == NULL) {
00053         fprintf(stderr, "can't make sequencing DAG\n");
00054         exit(1);
00055     }
00056 
00057     printf("\n**********************************************\n");
00058     printf("Beginning a sequence ...\n\n");
00059 }
00060 
00061 
00069 double grpc_sequence_end(int n, ...) {
00070     int status;
00071     double bt, et;
00072     va_list arg_list;
00073 
00074     va_start(arg_list, n);
00075 
00076     /* ---------------------- analyze and schedule DAG --------------------- */
00077 
00078     printf("Analyzing and building the DAG ...\n");
00079     /* analyze the dependencies of the
00080        current sequencing DAG */
00081     if ((status = analyze_dep_GS_DAG(GS_SEQ_DAG)) < 0) {
00082         fprintf(stderr, "error analyzing DAG\n");
00083         exit(1);
00084     }
00085 
00086     /* output the analyzed DAG to a dot graph */
00087     output_GS_DAG_to_dot(GS_SEQ_DAG, "pre_analysis.dot"); 
00088 
00089     printf("Post-analyzing the DAG ...\n");
00090     /* post analysis for DAG optimization */
00091     if ((status = post_analysis_GS_DAG(GS_SEQ_DAG, arg_list, n)) < 0) {
00092         fprintf(stderr, "error doing post-DAG-analysis\n");
00093         exit(1);
00094     }
00095 
00096     /*output the analyzed DAG to a dot graph */
00097     output_GS_DAG_to_dot(GS_SEQ_DAG, "post_analysis.dot");
00098  
00099     printf("Mapping the DAG to servers ...\n");
00100     /* map the DAG to servers - scheduling */   
00101     if ((status = map_to_servers_GS_DAG(GS_SEQ_DAG, AGENT)) < 0) {
00102         fprintf(stderr, "error mapping DAG to servers\n");
00103         exit(1);
00104     }
00105 
00106     if (make_new_data_handle_list(GS_SEQ_DAG) < 0) {
00107         fprintf(stderr, "error creating data handle list\n");
00108         exit(1);
00109     }
00110 
00111     if (gs_seq_set_lfs_dsi_data_storage_path() < 0) {
00112         exit(1);
00113     }
00114     
00115     /* --------------------------- execute DAG ----------------------------- */
00116     printf("\nExecuting the DAG ...\n");
00117     
00118     bt = walltime();
00119     
00120     /* execute the DAG */
00121     if ((status = execute_GS_DAG(GS_SEQ_DAG)) < 0) {
00122         fprintf(stderr, "error executing DAG\n");
00123         exit(1);
00124     }
00125     
00126     et = walltime();
00127 
00128     /* ---------------------------- finalize ------------------------------- */
00129     /* turn off the sequencing mode */
00130     grpc_sequence_mode = OFF_MODE;
00131 
00132     /* free the DAG's memory */
00133     free_GS_DAG(GS_SEQ_DAG);
00134     GS_SEQ_DAG = NULL;
00135 
00136     /* free the data handle list */
00137     free_data_handle_list();
00138 
00139     /* remove all data files */
00140     if (chdir(DATA_SEND_FILE_PATH) < 0) {
00141         fprintf(stderr, "error changing directory\n");
00142         return -1;
00143     }
00144 
00145     system("rm *.dat");
00146 
00147     printf("\nSequence done.\n");
00148     printf("**********************************************\n\n");
00149 
00150     return et - bt;
00151 }
00152 
00153 
00162 int grpc_submit(char *name, ...) {
00163     gs_va_list *arg_list;
00164 
00165     if (name == NULL) return -1;
00166 
00167     arg_list = (gs_va_list *) malloc(sizeof(gs_va_list));
00168     if (arg_list == NULL) {
00169         perror("malloc");
00170         exit(1);
00171     }
00172 
00173     /* create the variable argument list */
00174     va_start(arg_list->args, name);
00175 
00176     /* insert a new node into the DAG */
00177     return insert_node_GS_DAG(GS_SEQ_DAG, name, arg_list, NULL);
00178 }
00179 
00180 
00189 int grpc_submit_arg_stack(char *name, grpc_arg_stack *arg_stack) {
00190     if (name == NULL || arg_stack == NULL) return -1;
00191     
00192     /* insert a new node into the DAG */
00193     return insert_node_GS_DAG(GS_SEQ_DAG, name, NULL, arg_stack);
00194 }
00195 
00196 
00204 int grpc_get_sequence_mode() {
00205     /* return the current sequencing mode */
00206     return grpc_sequence_mode;
00207 }
00208 
00209 
00217 GS_DAG_t *grpc_get_sequence() {
00218     return GS_SEQ_DAG;
00219 }