90 likes | 230 Views
CDT Static Analysis Features CDT Developer Summit - Ottawa. Beth Tibbitts tibbitts@us.ibm.com September 20, 2006. This work has been supported in part by the Defense Advanced Research Projects Agency (DARPA) under contract No. NBCH30390004. The Problem.
E N D
CDT Static Analysis FeaturesCDT Developer Summit - Ottawa Beth Tibbitts tibbitts@us.ibm.com September 20, 2006 This work has been supported in part by the Defense Advanced Research Projects Agency (DARPA) under contract No. NBCH30390004.
The Problem • Static Analysis of C programs is useful • Existing Abstract Syntax Tree (AST) in Eclipse CDT provides basic navigation and information, but needs more
CDT AST Extensions • Enhance existing CASTNode and Visitor • bottom-up traversal • Add other additional graphs: • Call Graph • Control Flow Graph • Data Dependence Graph • Traversal of these new graphs available in: • Topological Order • Reverse Topological Order
Bottom-up AST traversal org.eclipse.cdt.core.dom.ast.ASTVisitor org.eclipse.cdt.core.dom.ast.c.CASTVisitor Existing: public int visit(IASTxxx..){ return PROCESS_CONTINUE; } New: public int leave(IASTxxx..){ return PROCESS_CONTINUE; }
#include "mpi.h" #include "stdio.h" void foo(int x); void gee(int x); void kei(int x); void foo(int x){ x ++; gee(x); } void gee(int x){ x *= 3; kei(x); } void kei(int x){ x = x % 10; foo(x); } void a(int x){ x --; } int main3(int argc, char* argv[]){ int x = 0; foo(x); a(x); } Call Graph main foo a gee kei Recursive calls detected… A cycle is detected on foo, gee and kei
Control Flow Graph & Data Flow Dependence Graph– sample program if if (my_rank !=0){ /* create message */ sprintf(message, "Greetings from process %d!", my_rank); dest = 0; /* use strlen+1 so that '\0' get transmitted */ MPI_Send(message, strlen(message)+1, MPI_CHAR, dest, tag, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); } else{ printf("From process 0: Num processes: %d\n",p); for (source = 1; source < p; source++) { MPI_Recv(message, 100, MPI_CHAR, source, tag, MPI_COMM_WORLD, &status); printf("%s\n",message); } MPI_Barrier(MPI_COMM_WORLD); } /* shut down MPI */ MPI_Finalize(); free(array); return 0; } #include <stdio.h> #include <string.h> #include "mpi.h" // Sample MPI program int main(int argc, char* argv[]){ printf("Hello MPI World the original.\n"); int my_rank; /* rank of process */ int p; /* number of processes */ int source; /* rank of sender */ int dest; /* rank of receiver */ int tag=0; /* tag for messages */ char message[100], *tmp; /* storage for message */ MPI_Status status ; /* return status for receive */ int * array; /* start up MPI */ array = (int *)malloc(sizeof(int) * 10); MPI_Init(&argc, &argv); /* find out process rank */ MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); /* find out number of processes */ MPI_Comm_size(MPI_COMM_WORLD, &p); MPI_Barrier(MPI_COMM_WORLD); for
Control Flow Graph entry A B printf MPI_Comm_rank() free(array) Int my_rank MPI_Comm_size return 0 Int p if MPI_Barrier() exit Int source my_rank != 0 Int dest sprintf printf Int tag = 0 dest = 0 source = 1 Char message[100], *tmp for MPI_Send() source < p MPI_Status status MPI_Barrier() MPI_Barrier() MPI_Recv Int *array printf (join block) array = malloc() source ++ MPI_Finalize() MPI_Init() B A
Work in Progress (graph not complete) Data Dependence Graph (DDG) entry A B printf MPI_Comm_rank() free(array) Int my_rank MPI_Comm_size return 0 Int p MPI_Barrier() exit Int source my_rank != 0 Int dest sprintf printf Control flow Control flow Int tag = 0 dest = 0 Data flow source = 1 Char message[100], *tmp MPI_Send() source < p MPI_Status status MPI_Barrier() MPI_Barrier() MPI_Recv Int *array printf (join block) array = malloc() source ++ MPI_Finalize() MPI_Init() B A
Summary • MPI Barrier Analysis uses these structures • Is this valuable as an addition to CDT? • Other Future plans • Parallel Tools Platform (PTP) Analysis: • Static and Dynamic Analysis of MPI, OpenMP, and LAPI programs for detection of common errors • Code Refactorings for Performance Optimization, e.g. refactoring for improved computation / communication overlap