Пример #1
0
/* Reads and parses input from the input file.
 * Also adds input to the two lists.
 */
void readInput(FILE* inputFile, CustomerList* cList, OrderList* oList) {
    
    int id;
    char last_name[25];
    char first_name[25];
    char item_name[20];
    float item_price;
    int item_quantity;
    
    while (1) {
        if( fscanf(inputFile,  "%d %s %s %s $%f %d",
                   &id, last_name, first_name, item_name, &item_price, &item_quantity) == EOF){
            printf("End of file\n");
            break;
        }
        
        /*printf("%d %s %s %s $%.2f %d\n",
                   id, last_name, first_name, item_name, item_price, item_quantity);*/
        
        //check if customer is already in CustomerList.
        if (containsCust(cList, id)) {
            addToCust(cList, id, item_price, item_quantity);
            
            //Add to list of orders
            Order* ord = createOrder(id, item_name, item_price, item_quantity);
            pushOList(oList, ord);
          
            
            
        } else {
            
            char combine_name[50];
            strcpy(combine_name, last_name);
            strcat(combine_name, " ");
            strcat(combine_name, first_name);
            
            //Add to list of customers
            Customer* cust = createCustomer(id, combine_name, item_price, item_quantity);
            pushCList(cList, cust);
            
            //Add to list of orders
            Order* ord = createOrder(id, item_name, item_price, item_quantity);
            pushOList(oList, ord);
           
            
        }
        
    }
}
Пример #2
0
void cpuColorSpinorField::create(const QudaFieldCreate create) {
  if (pad != 0) {
    errorQuda("Non-zero pad not supported");
  }
  
  if (precision == QUDA_HALF_PRECISION) {
    errorQuda("Half precision not supported");
  }

  if (gammaBasis != QUDA_DEGRAND_ROSSI_GAMMA_BASIS) {
    errorQuda("Basis not implemented");
  }

  if (fieldOrder != QUDA_SPACE_COLOR_SPIN_FIELD_ORDER && 
      fieldOrder != QUDA_SPACE_SPIN_COLOR_FIELD_ORDER) {
    errorQuda("Field order %d not supported", fieldOrder);
  }

  if (create != QUDA_REFERENCE_FIELD_CREATE) {
    v = (void*)malloc(bytes);
    init = true;
  }
 
  createOrder(); // need to do this for references?
}
Пример #3
0
void cpuColorSpinorField::create(const QudaFieldCreate create) {
  if (pad != 0) {
    errorQuda("Non-zero pad not supported");
  }
  
  if (precision == QUDA_HALF_PRECISION) {
    errorQuda("Half precision not supported");
  }

  if (fieldOrder != QUDA_SPACE_COLOR_SPIN_FIELD_ORDER && 
      fieldOrder != QUDA_SPACE_SPIN_COLOR_FIELD_ORDER &&
      fieldOrder != QUDA_QOP_DOMAIN_WALL_FIELD_ORDER) {
    errorQuda("Field order %d not supported", fieldOrder);
  }

  if (create != QUDA_REFERENCE_FIELD_CREATE) {
    // array of 4-d fields
    if (fieldOrder == QUDA_QOP_DOMAIN_WALL_FIELD_ORDER) {
      int Ls = x[nDim-1];
      v = (void**)malloc(Ls * sizeof(void*));
      for (int i=0; i<Ls; i++) ((void**)v)[i] = (void*)malloc(bytes / Ls);
    } else {
      v = (void*)malloc(bytes);
      init = true;
    }
  }
 
  createOrder(); // need to do this for references?
}
Пример #4
0
void *producer(void *args) {
    FILE *file;
    char *category;
    char *linebuffer;
    char *title;
    char *file_path;
    const char *delims = "|\n\r";
    float price;
    int c_id;
    orderPTR order;
    size_t len;
    ssize_t read;

    len = 0;
    file_path = (char*) args;
    int fileintegrity = checkFile(file_path);


   
    if (!fileintegrity) 
    {
        printf("Problem opening file :( \n");
        exit(EXIT_FAILURE);
    }

    file = fopen(file_path, "r");

    linebuffer = NULL;

    while ( (read = getline(&linebuffer, &len, file)) != -1 ) 
    {

        title = strtok(linebuffer, delims);
        price = atof(strtok(NULL, delims));
        c_id = atoi(strtok(NULL, delims));
        category = strtok(NULL, delims);

   /*    for (int i = 0; i < 500; i++)
       {
        if (!strcmp(category_array[i], category))
        {
            break;
        }
       }  */

        order = createOrder(title, price, c_id, category);
        pthread_mutex_lock(&queue->mutex);
        enqueue(queue,(void*) order);
        pthread_mutex_unlock(&queue->mutex);
        pthread_cond_signal(&queue->NOTempty);

    }

    alldone = 1;
    pthread_cond_broadcast(&queue->NOTempty);
    free(linebuffer);
    fclose(file);
    return NULL;
}