gs_dag_utils.c

Go to the documentation of this file.
00001 /********************************************************************/
00002 /*                          gs_dag_utils.c                          */
00003 /*        he utilization functions for the GridSolve DAG API        */
00004 /*                       Yinan Li, 05/17/2007                       */
00005 /********************************************************************/
00006 
00007 
00008 #include "gs_dag.h"
00009 #include "gs_sequence.h"
00010 
00011 
00020 int output_GS_DAG_to_dot(GS_DAG_t *dag, char *fname) {
00021     FILE *fp;
00022     GS_DAG_Node_t *node;
00023     GS_DAG_Dep_t *dep;
00024     char *pnode, *cnode;
00025     int plevel, clevel;
00026 
00027 
00028     if (dag == NULL) {
00029         fprintf(stderr, "null input DAG\n");
00030         return -1;
00031     }
00032 
00033     if (dag->num_nodes == 0 || dag->num_deps == 0) return -1;
00034 
00035     fp = fopen(fname, "w");
00036     if (fp == NULL) {
00037         fprintf(stderr, "can't open file %s\n", fname);
00038         return -1;
00039     }
00040 
00041     fprintf(fp, "digraph DAG {\n"); /* start */
00042     /* first output all the nodes (name) */
00043     for (node = dag->head_node; node != NULL; node = node->next) {
00044         fprintf(fp, "\t%s_%d;\n", node->func_name, node->sched_level);
00045     }
00046 
00047     /* next output all the dependencies as edges */
00048     for (dep = dag->head_dep; dep != NULL; dep = dep->next) {
00049         /* the name of parent and child nodes */
00050         pnode = dep->pnode->func_name;
00051         cnode = dep->cnode->func_name;
00052 
00053         /* the schedulng levels of parent and child nodes */
00054         plevel = dep->pnode->sched_level;
00055         clevel = dep->cnode->sched_level;
00056 
00057         /* draw different types of edges for
00058            different types of dependencies */
00059         switch (dep->dep_type) {
00060             case INPUT_AFTER_OUTPUT_DEPENDENCY:
00061                 /* outputs black, forward edge */
00062                 fprintf(fp, 
00063                 "\t%s_%d -> %s_%d [style=bold, label=\"RAW\", fontsize=12];\n",
00064                 pnode, plevel, cnode, clevel);
00065                 break;
00066             case OUTPUT_AFTER_INPUT_DEPENDENCY:
00067                 /* outputs blue, backward edge */
00068                 fprintf(fp,
00069                 "\t%s_%d -> %s_%d %s;\n",
00070                 pnode, plevel, cnode, clevel,
00071                 "[color=blue, label=\"WAR\", fontcolor=blue, fontsize=12]");
00072                 break;
00073             case OUTPUT_AFTER_OUTPUT_DEPENDENCY:
00074                 /* outputs red, bi-direction edge */
00075                 fprintf(fp, 
00076                 "\t%s_%d -> %s_%d %s;\n",
00077                 pnode, plevel, cnode, clevel,
00078                 "[color=red, label=\"WAW\", fontcolor=red, fontsize=12]");
00079                 break;
00080             case CONSERVATIVE_SCALAR_DEPENDENCY:
00081                 /* output green, indirected edge */
00082                 fprintf(fp,
00083                 "\t%s_%d -> %s_%d %s;\n",
00084                 pnode, plevel, cnode, clevel,
00085                 "[color=green, label=\"SCALAR\", fontcolor=green, fontsize=12]");
00086                 break;
00087             default:
00088                 break;
00089         }
00090     }
00091     fprintf(fp, "}\n"); /* end */
00092     fclose(fp);
00093     
00094     return 0;
00095 }
00096 
00097 
00106 int verify_object_type(gs_argument_t *argp) {
00107     int mode;
00108     
00109     mode = grpc_get_sequence_mode();
00110 
00111     /* under conservative mode, scalar arguments
00112        are invalid for reference verification */
00113     if (mode == CONSERVATIVE_MODE &&
00114         argp->objecttype == GS_SCALAR)
00115         return 0;
00116 
00117     /* under restrictive mode, scalar arguments
00118        are valid for reference verification */
00119     if (mode == RESTRICTIVE_MODE &&
00120         argp->objecttype == GS_SCALAR)
00121         return 1;
00122 
00123     /* under normal mode, ignore scalar arguments */
00124     if (argp->objecttype == GS_VECTOR ||
00125         argp->objecttype == GS_MATRIX ||
00126         argp->objecttype == GS_SPARSEMATRIX ||
00127         argp->objecttype == GS_FILE)
00128         return 1;
00129 
00130     return 0;
00131 }
00132 
00133 
00141 int compare_object(gs_argument_t *largp, gs_argument_t *rargp) {
00142     int mode;
00143     
00144     mode = grpc_get_sequence_mode();
00145     
00146     /* under normal or conservative mode, comparison 
00147        among scalar argument references is invalid */
00148     if (mode != RESTRICTIVE_MODE &&
00149         (largp->objecttype == GS_SCALAR ||
00150          rargp->objecttype == GS_SCALAR))
00151         return 1;
00152 
00153     /* under restrictive mode, comparison among
00154        scalar argument references is valid */
00155     if (mode == RESTRICTIVE_MODE &&
00156         (largp->objecttype == GS_SCALAR &&
00157          rargp->objecttype == GS_SCALAR) &&
00158         largp->datatype == rargp->datatype) {
00159 
00160     }
00161 
00162     /* comparison among nonscalar argument references */
00163     if (largp->objecttype == rargp->objecttype &&
00164         largp->datatype == rargp->datatype &&
00165         largp->data == rargp->data)
00166         return 0;
00167 
00168     return 1;
00169 }
00170 
00171 
00176 int if_passed_back(va_list arg_list, int n, gs_argument_t *argptr) {
00177     int i;
00178     void *arg;
00179 
00180     for (i = 0; i < n; i++) {
00181         arg = va_arg(arg_list, void*);
00182         if (argptr->data == arg) return 1;
00183     }
00184     va_end(arg_list);
00185 
00186     return 0;
00187 }