Пример #1
0
void elg_readcb_ENTER_CS(elg_ui4 lid, elg_d8 time, elg_ui4 csid,
       elg_ui1 metc, elg_ui8 metv[], void* userdata) {
  lid = locmap[lid];
  if ( need_usr && stk_top(lid)->reg == ELG_NO_ID ) {
    stk_push(lid, state_user, time);
    wbytes += VTF3_WriteDownto(fcb, time*1.0e+10, state_user,
                               (unsigned int) lid, VTF3_SCLNONE);
  }
  stk_push(lid, csitetab[csid].erid, time);
  wbytes += VTF3_WriteDownto(fcb, time*1.0e+10, (int) csitetab[csid].erid,
                             (unsigned int) lid, scl_of_csite(csid));
  genWriteCOUNTER(lid, time, metc, metv);
}
int main()
{
    int i;
    
    /* Populate stack */
    for (i = 0; i < 11; ++i)
        stk_push(i);
    if (stk_error())
        puts("stack error");
    printf("The last element pushed was %d\n",
           stk_top());
    
    /* Pop/print stack */
    while (stk_size() > 0)
        printf("%d ", stk_pop());
    putchar('\n');
    if (!stk_error())
        puts("no stack error");
    return 0;
}
Пример #3
0
void elg_readcb_ENTER(elg_ui4 lid, elg_d8 time, elg_ui4 rid,
       elg_ui1 metc, elg_ui8 metv[], void* userdata) {
  lid = locmap[lid];
  if ( need_usr && stk_top(lid)->reg == ELG_NO_ID ) {
    stk_push(lid, state_user, time);
    wbytes += VTF3_WriteDownto(fcb, time*1.0e+10, state_user,
                               (unsigned int) lid, VTF3_SCLNONE);
  }
  stk_push(lid, rid, time);
  if ( writeOMP && statetab[rid].act == act_omp
                && statetab[rid].type != ELG_FUNCTION ) {
    wbytes += VTF3_WriteOpenmpenter(fcb, time*1.0e+10, (unsigned int) lid,
	                            (unsigned int) statetab[rid].type,
                                    (unsigned int) rid,
                                    scl_of_state(rid));
  } else {
    wbytes += VTF3_WriteDownto(fcb, time*1.0e+10, (int) rid,
                              (unsigned int) lid, scl_of_state(rid));
  }
  genWriteCOUNTER(lid, time, metc, metv);
}
Пример #4
0
void elg_readcb_EXIT_TRACING(elg_ui4 lid, elg_d8 time,
       elg_ui1 metc, elg_ui8 metv[], void* userdata) {

  MYDATA* md = (MYDATA*) userdata;
  StackNode *n, *p;
  int i;
  struct {
    int16_t length;
    char *string;
  } val;


  lid = locmap[lid];
  //if ( rlid != ELG_NO_ID ) rlid = locmap[rlid];
  n = stk_pop(lid);

    if(primitives == NULL) {
    primitives = (PRIMITIVES_List*) malloc(sizeof(struct _primitives_list));
    last_primitive = primitives;
    primitives->size = 0;
  } else {
    last_primitive->next = (PRIMITIVES_List*) malloc(sizeof(struct _primitives_list));
    last_primitive = last_primitive->next;
  }
  /* New Event */
  primitives->size++;

  last_primitive->next = NULL;
  last_primitive->prim = (DRAW_Primitive *) malloc(sizeof(DRAW_Primitive));
  last_primitive->prim->starttime = n->tim;
  last_primitive->prim->endtime = time;
  last_primitive->prim->type_idx = ST_EPIK;
  last_primitive->prim->num_tcoords = 2;
  last_primitive->prim->tcoords = (double*) malloc(2*sizeof(double));
  last_primitive->prim->tcoords[0] = n->tim;
  last_primitive->prim->tcoords[1] = time;
  last_primitive->prim->num_ycoords = 2;
  last_primitive->prim->ycoords = (int*) malloc(2*sizeof(int));
  last_primitive->prim->ycoords[0] = lid;
  last_primitive->prim->ycoords[1] = lid;
  p = stk_top(lid);
  if(!strcmp(statetab[p->reg].name,"MPI_Init")) {
    last_primitive->prim->num_info = sizeof(int16_t)+21*sizeof(char);
    last_primitive->prim->info = (char*) malloc(21*sizeof(char));
    strcpy(last_primitive->prim->info, "Epik - Initialization");
  
    last_primitive->prim->info = (char*) malloc(last_primitive->prim->num_info*sizeof(char));
    val.string = (char *) malloc(21*sizeof(char));
    strcpy(val.string, "Epik - Initialization");
    val.length = 21;
    
    if(ELG_BYTE_ORDER == ELG_LITTLE_ENDIAN) {
      elg_swap(&val.length, sizeof(int16_t));
    }
    
    memcpy(last_primitive->prim->info, &val.length, sizeof(int16_t));
    memcpy(last_primitive->prim->info+sizeof(int16_t), val.string, 21*sizeof(char));
  } else if(!strcmp(statetab[p->reg].name,"MPI_Finalize")){
    last_primitive->prim->num_info = sizeof(int16_t)+19*sizeof(char);
    last_primitive->prim->info = (char*) malloc(19*sizeof(char));
    strcpy(last_primitive->prim->info, "Epik - Finalization");
  
    last_primitive->prim->info = (char*) malloc(last_primitive->prim->num_info*sizeof(char));
    val.string = (char *) malloc(19*sizeof(char));
    strcpy(val.string, "Epik - Finalization");
    val.length = 19;
    
    if(ELG_BYTE_ORDER == ELG_LITTLE_ENDIAN) {
      elg_swap(&val.length, sizeof(int16_t));
    }
    
    memcpy(last_primitive->prim->info, &val.length, sizeof(int16_t));
    memcpy(last_primitive->prim->info+sizeof(int16_t), val.string, 19*sizeof(char));
  } else {
    last_primitive->prim->num_info = sizeof(int16_t)+12*sizeof(char);
    last_primitive->prim->info = (char*) malloc(12*sizeof(char));
    strcpy(last_primitive->prim->info, "Epik - Flush");
  
    last_primitive->prim->info = (char*) malloc(last_primitive->prim->num_info*sizeof(char));
    val.string = (char *) malloc(12*sizeof(char));
    strcpy(val.string, "Epik - Flush");
    val.length = 12;
    
    if(ELG_BYTE_ORDER == ELG_LITTLE_ENDIAN) {
      elg_swap(&val.length, sizeof(int16_t));
    }
    
    memcpy(last_primitive->prim->info, &val.length, sizeof(int16_t));
    memcpy(last_primitive->prim->info+sizeof(int16_t), val.string, 12*sizeof(char));
  }
}
Пример #5
0
/*
 * Check if the given string is balanced
 */
int checkBalanced(StackPtr stack, char* n, int debug) {

    //go through the string
    int x = 0; //keep track of where the unbalanced symbol is
    int unbalanced = 0;
    int miss = 0;
    int i;
    for(i = 0; i < strlen(n) - 1; i++) {

        //If we encounter an opening symbol
        if(n[i] == '(' || n[i] == '{' || n[i] == '[' || n[i] == '<') {

            if(debug) {
                printf("Debug mode: Pushing to stack: %c\n", n[i]);
            }
            stk_push(stack, n[i], debug);
            x++;

        }

       //if we encounter a closing symbol
        if(n[i] == ')' || n[i] == '}' || n[i] == ']' || n[i] == '>'){

            //if closing is encountered next, if correct closing bracket pop from stack
            if(n[i] == ')') {

                if(stk_top(stack) == '(') {
                    if(debug) {
                        printf("Debug mode: Popping from stack: %c\n", stk_top(stack));
                    }
                    stk_pop(stack);
                } else {
                    miss = 1;
                    unbalanced = 1;
                }

            } else if(n[i] == '}') {

                if(stk_top(stack) == '{') {
                    if(debug) {
                        printf("Debug mode: Popping from stack: %c\n", stk_top(stack));
                    }
                    stk_pop(stack);
                } else {
                    miss = 2;
                    unbalanced = 1;
                }

            } else if(n[i] == ']') {

                if(stk_top(stack) == '[') {
                    if(debug) {
                        printf("Debug mode: Popping from stack: %c\n", stk_top(stack));
                    }
                    stk_pop(stack);
                } else {
                    miss = 3;
                    unbalanced = 1;
                }

            } else if(n[i] == '>') {

                if(stk_top(stack) == '<') {
                    if(debug) {
                        printf("Debug mode: Popping from stack: %c\n", stk_top(stack));
                    }
                    stk_pop(stack);
                } else {
                    miss = 4;
                    unbalanced = 1;
                }

            }

        }

    }

    if(stk_is_empty(stack) && !unbalanced) {

        printf("\n%s", n);
        printf("Expression is Balanced!\n\n\n");
        return 1;

    } else {

        printf("\n%s\n", n);

        int i;
        for(i = 0; i < x; i++) {
            printf(" ");
        }
        printf("^");

        if(miss == 1) {
            printf(" missing (");
        } else if(miss == 2) {
            printf(" missing {");
        } else if(miss == 3) {
            printf(" missing [");
        } else if(miss == 4) {
            printf(" missing <");
        }

        printf("\n\n\n");

        return 0;

    }

}