/* ----------------------------------------------------------------------
 * N_VMake Test
 *
 * NOTE: This routine depends on N_VConst to check vector data.
 * --------------------------------------------------------------------*/
int Test_N_VMake(HYPRE_ParVector W, int myid)
{
  int failure;
  /* double   start_time, stop_time; */
  N_Vector X;
  int local_length = hypre_ParVectorLastIndex(W) 
                     - hypre_ParVectorFirstIndex(W) + 1;

  /* clone vector */
  /* start_time = get_time(); */  
  X = N_VMake_ParHyp(W);
  /* stop_time = get_time();  */

  /* check cloned vector */
  if (X == NULL) {
    printf(">>> FAILED test -- N_VMake, Proc %d \n", myid);
    printf("    After N_VMakeEmpty, X == NULL \n \n");
    return(1);
  } 

  /* check cloned vector data */
  if (!has_data(X)) {
    printf(">>> FAILED test -- N_VMake, Proc %d \n", myid);
    printf("    Vector data == NULL \n \n");
    N_VDestroy(X);
    return(1);
  }    

  N_VConst(ONE,X);
  failure = check_ans(ONE, X, local_length);
  if (failure) {
    printf(">>> FAILED test -- N_VMake, Proc %d \n", myid);
    printf("    Failed N_VConst check \n \n");
    N_VDestroy(X);
    return(1);
  }    

  N_VDestroy(X); 

  if (myid == 0) {
    printf("    PASSED test -- N_VMake \n");
    /* PRINT_TIME("    N_VMake Time: %22.15e \n \n", stop_time - start_time); */
  }

  return(0);
}
Exemple #2
0
int main(int argc, char ** argv) {
    int num = 4095, len = 0, c, num_arr_argv;
    char delim = '\n';
    while ((c = getopt(argc, argv, "nzb:")) != -1) {
        if (c == 'n') {
            delim = '\n';
        }           
        if (c == 'z') {
            delim = '\0';
        }
        if (c == 'b') {
            num = atoi(optarg);
        }
    }
    char * buffer = (char *) malloc(num + 1);
    if (buffer == NULL) {
        return 1;
    }
    char ** arr_argv = (char **) malloc(argc - optind + 1);
    if (arr_argv == NULL) {
        free(buffer);
        return 2;
    }
    int i;
    for (i = optind; i < argc; i++) {
        if (strcmp(argv[i], "{}") == 0) {
            num_arr_argv = i - optind;
        }
        arr_argv[i - optind] = argv[i];
    }
    arr_argv[argc - optind] = 0;
    while (1) {
        int read_res = read(IN, buffer + len, num + 1 - len);
        if (read_res < 0) {
            free(buffer);
            free(arr_argv);
            return 3;
        }
        if (read_res == 0) {
            if (len <= 0 || len == num) {
                free(buffer);
                free(arr_argv);
                return 4;
            }
            if (len > 0 && len < num) {
                check_ans(arr_argv, num_arr_argv, buffer, len);
            }
            break;
        }
        int left = len;
        int right = read_res + len;
        while (left < right) {
            if (buffer[left] == delim) {
                left++;
                check_ans(arr_argv, num_arr_argv, buffer, left);
                memmove(buffer, buffer + left, right - left);
                right = right - left;
                left = 0;
            } else {
                left++;
            }
        }
        if (left == num + 1) {
            free(buffer);
            free(arr_argv);
            return 5;
        } else {
            len = left;
        }
    }
    free(buffer);
    free(arr_argv);
    return 0;
}