Exemplo n.º 1
0
int get_job_time()
{
    struct timeval t1, t2;
    gettimeofday(&t1, NULL);
    do_job();
    gettimeofday(&t2, NULL);
    int job_time = 1000 * (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000;
    return job_time;
}
Exemplo n.º 2
0
void* vina_worker(void* arg)
{
    struct para* work_para = (struct para*)arg;
    char work_path[MAX_PATH];
    int my_job;
    while ((my_job = get_job(work_para->jp, work_para->t)) != NO_JOB) {
        get_workpath(work_para->home_path, my_job, work_path);
        setup(work_para->cf, work_para->home_path, my_job, work_para->t);
        do_job(my_job, work_para->t, work_path);
        cleanup(work_path, work_para->cf->gather_loc, work_para->t, work_para->cf->outfile, my_job);
    }
    printf("Done!");
    free(work_para);
    return NULL;
}
Exemplo n.º 3
0
void* dispatch_job () {

	struct job *job;

	while(1) {
		pthread_mutex_lock(&mutex);
		job = get_job();
		pthread_mutex_unlock(&mutex);

		if (job) {
			do_job(job);
			free(job);
		}
		else {
			pthread_exit(NULL);
		}
	}
}
Exemplo n.º 4
0
int main(int argc, char const* argv[])
{
    struct stat sb;
    int ubootsize;
    char *uboot;
    int fd, ofd;
    char *buf;
    int bytes;

    printf("    open file : %s \n", argv[1]);
    if ((fd = open(argv[1],  O_RDONLY, (mode_t)(0))) == -1){
        perror("Cannot open filen");
    }
    if (fstat(fd, &sb) == -1) { /* To obtain file size */
        return -1;
    }

    if((buf = malloc(sb.st_size)) == NULL){
        perror("malloc error!");
    }
    
    printf("    read file  \n");
    bytes = read(fd, buf, sb.st_size);
    if ( bytes != sb.st_size){
        perror("partial read or error!");
    }

    printf("    do job  \n");
    uboot = do_job(&ubootsize, buf);

    printf("save uboot to uboot.bin\n");
    if ((ofd = open("uboot.bin",  O_WRONLY | O_CREAT | O_TRUNC, (mode_t)(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))) == -1){
        perror("Cannot open filen");
    }
    
    bytes = write(ofd, uboot, ubootsize);
    if (bytes != ubootsize) {
        perror("can't save uboot.bin");
    }
    return 0;
}
Exemplo n.º 5
0
/**
 * Iterates through job list and calls do_job for each job.
 * @param _work Handle work object.
 */
static void work_func( void * _work )
{
    hb_work_t  * work = _work;
    hb_job_t   * job;

    hb_log( "%d job(s) to process", hb_list_count( work->jobs ) );

    while( !*work->die && ( job = hb_list_item( work->jobs, 0 ) ) )
    {
        hb_list_rem( work->jobs, job );
        job->die = work->die;
        *(work->current_job) = job;
        InitWorkState( job->h );
        do_job( job );
        *(work->current_job) = NULL;
    }

    *(work->error) = HB_ERROR_NONE;

    free( work );
}
Exemplo n.º 6
0
int mpi_main(int argc, char **argv,
             job_t (send_jobs)(filter_t *, unsigned char **, int, int),
             job_t (get_job)(filter_t *)) {
    int rank, image_width, image_height;
    filter_t filter;
    job_t job;
    double starttime;
    unsigned char ** result;

    MPI_Init(&argc, &argv);

    starttime = MPI_Wtime();
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    // Init
    if (rank == 0) {
        // Read in image and filter and send to workers
        if (argc < 3 || argc > 4) {
            fprintf(stderr, "USAGE: %s filter.txt input.pnm [output.pnm]\n",
                    argv[1]);
            return 1;
        }

        const char * filter_path = argv[1];
        const char * image_path  = argv[2];
        const char * output_path = argv[argc == 3 ? 2 : 3];

        unsigned char ** image;

        filter.filter = read_filter(filter_path, &filter.width, &filter.height);
        image = read_image(image_path, &image_width, &image_height);

        send_filter(&filter);
        job = send_jobs(&filter, image, image_width, image_height);

        result = do_job(&job, &filter);

        LOG("Fetching results.");
        fetch_results(result, image_width);

        LOG("Writing output");
        write_image(output_path, result, job.width, job.height);
    } else {
        // Receive filter and job
        filter = get_filter();
        job = get_job(&filter);

        result = do_job(&job, &filter);

        LOG("Sending results");
        send_result(&job, result);
    }

    // Cleanup
    /* free_filter(filter.filter, filter.height); */
    /* free_image(job.image); */
    /* free_image(result); */

    starttime = MPI_Wtime() - starttime;
    if (rank == 0)
        printf("%f\n", starttime);

    MPI_Finalize();

    return 0;
}
Exemplo n.º 7
0
int main()
{

    struct timeval t1, t2;
    printf("Input a number representing the number of timers for factorial: ");
    scanf("%d",&ROUND);


    printf("Input a number representing the rate of period over processing: ");
    scanf("%d",&PERIOD_PRO_RATIO);

    printf("Input a number representing the number of repeating jobs: ");
    scanf("%d",&JOB_NUM);

    // estimate the job time
    int comp_time = get_job_time();
    int period = PERIOD_PRO_RATIO * comp_time;

    printf("cal job time: %d ms \n", comp_time);

    // register in the module

    int pid = register_proc(period, comp_time);

    printf("computation time: %d ms, period: %d ms \n", comp_time,period);

    // verify the process was admitted
    if (!verify(pid))
    {
        printf("process %d was not admitted!\n", pid);
        exit(1);
    }

    yield(pid);


    // real-time loop
    int i;
    for (i=0; i<JOB_NUM; i++){
        system("cat /proc/mp2/status");

        gettimeofday(&t1,NULL);
        printf("Start Time of this job with ID %d : %d sec \n",pid,t1.tv_sec);

        do_job();

        gettimeofday(&t2,NULL);
        printf("End Time of this job with ID %d : %d sec \n",pid,t2.tv_sec);

        yield(pid);

    }

    deregister(pid);

    // read the list of processes
    //system("cat /proc/mp2/status");
    printf("Test application ends.\n");

    return 0;
}
Exemplo n.º 8
0
/* The public routine for compression.  See blosc.h for docstrings. */
int blosc_compress(int clevel, int doshuffle, size_t typesize, size_t nbytes,
		   const void *src, void *dest, size_t destsize)
{
  uint8_t *_dest=NULL;         /* current pos for destination buffer */
  uint8_t *flags;              /* flags for header.  Currently booked:
                                  - 0: shuffled?
                                  - 1: memcpy'ed? */
  uint32_t nbytes_;            /* number of bytes in source buffer */
  uint32_t nblocks;            /* number of total blocks in buffer */
  uint32_t leftover;           /* extra bytes at end of buffer */
  uint32_t *bstarts;           /* start pointers for each block */
  uint32_t blocksize;          /* length of the block in bytes */
  uint32_t ntbytes = 0;        /* the number of compressed bytes */
  uint32_t *ntbytes_;          /* placeholder for bytes in output buffer */
  uint32_t maxbytes = (uint32_t)destsize;  /* maximum size for dest buffer */

  /* Check buffer size limits */
  if (nbytes > BLOSC_MAX_BUFFERSIZE) {
    /* If buffer is too large, give up. */
    fprintf(stderr, "Input buffer size cannot exceed %d MB\n",
            BLOSC_MAX_BUFFERSIZE / MB);
    exit(1);
  }
  /* We can safely do this assignation now */
  nbytes_ = (uint32_t)nbytes;

  /* Compression level */
  if (clevel < 0 || clevel > 9) {
    /* If clevel not in 0..9, print an error */
    fprintf(stderr, "`clevel` parameter must be between 0 and 9!\n");
    return -10;
  }

  /* Shuffle */
  if (doshuffle != 0 && doshuffle != 1) {
    fprintf(stderr, "`shuffle` parameter must be either 0 or 1!\n");
    return -10;
  }

  /* Check typesize limits */
  if (typesize > BLOSC_MAX_TYPESIZE) {
    /* If typesize is too large, treat buffer as an 1-byte stream. */
    typesize = 1;
  }

  /* Get the blocksize */
  blocksize = compute_blocksize(clevel, (uint32_t)typesize, nbytes_);

  /* Compute number of blocks in buffer */
  nblocks = nbytes_ / blocksize;
  leftover = nbytes_ % blocksize;
  nblocks = (leftover>0)? nblocks+1: nblocks;

  _dest = (uint8_t *)(dest);
  /* Write header for this block */
  _dest[0] = BLOSC_VERSION_FORMAT;         /* blosc format version */
  _dest[1] = BLOSCLZ_VERSION_FORMAT;       /* blosclz format version */
  flags = _dest+2;                         /* flags */
  _dest[2] = 0;                            /* zeroes flags */
  _dest[3] = (uint8_t)typesize;            /* type size */
  _dest += 4;
  ((uint32_t *)_dest)[0] = sw32(nbytes_);  /* size of the buffer */
  ((uint32_t *)_dest)[1] = sw32(blocksize);/* block size */
  ntbytes_ = (uint32_t *)(_dest+8);        /* compressed buffer size */
  _dest += sizeof(int32_t)*3;
  bstarts = (uint32_t *)_dest;             /* starts for every block */
  _dest += sizeof(int32_t)*nblocks;        /* space for pointers to blocks */
  ntbytes = (uint32_t)(_dest - (uint8_t *)dest);

  if (clevel == 0) {
    /* Compression level 0 means buffer to be memcpy'ed */
    *flags |= BLOSC_MEMCPYED;
  }

  if (nbytes_ < MIN_BUFFERSIZE) {
    /* Buffer is too small.  Try memcpy'ing. */
    *flags |= BLOSC_MEMCPYED;
  }

  if (doshuffle == 1) {
    /* Shuffle is active */
    *flags |= BLOSC_DOSHUFFLE;              /* bit 0 set to one in flags */
  }

  /* Populate parameters for compression routines */
  params.compress = 1;
  params.clevel = clevel;
  params.flags = (int32_t)*flags;
  params.typesize = (uint32_t)typesize;
  params.blocksize = blocksize;
  params.ntbytes = ntbytes;
  params.nbytes = nbytes_;
  params.maxbytes = maxbytes;
  params.nblocks = nblocks;
  params.leftover = leftover;
  params.bstarts = bstarts;
  params.src = (uint8_t *)src;
  params.dest = (uint8_t *)dest;

  if (!(*flags & BLOSC_MEMCPYED)) {
    /* Do the actual compression */
    ntbytes = do_job();
    if ((ntbytes == 0) && (nbytes_+BLOSC_MAX_OVERHEAD <= maxbytes)) {
      /* Last chance for fitting `src` buffer in `dest`.  Update flags
       and do a memcpy later on. */
      *flags |= BLOSC_MEMCPYED;
      params.flags |= BLOSC_MEMCPYED;
    }
  }

  if (*flags & BLOSC_MEMCPYED) {
    if (nbytes_+BLOSC_MAX_OVERHEAD > maxbytes) {
      /* We are exceeding maximum output size */
      ntbytes = 0;
    }
    else if (((nbytes_ % L1) == 0) || (nthreads > 1)) {
      /* More effective with large buffers that are multiples of the
       cache size or multi-cores */
      params.ntbytes = BLOSC_MAX_OVERHEAD;
      ntbytes = do_job();
    }
    else {
      memcpy((uint8_t *)dest+BLOSC_MAX_OVERHEAD, src, nbytes_);
      ntbytes = nbytes_ + BLOSC_MAX_OVERHEAD;
    }
  }

  /* Set the number of compressed bytes in header */
  *ntbytes_ = sw32(ntbytes);

  assert((int32_t)ntbytes <= (int32_t)maxbytes);
  return ntbytes;
}
Exemplo n.º 9
0
/* The public routine for decompression.  See blosc.h for docstrings. */
int blosc_decompress(const void *src, void *dest, size_t destsize)
{
  uint8_t *_src=NULL;            /* current pos for source buffer */
  uint8_t *_dest=NULL;           /* current pos for destination buffer */
  uint8_t version, versionlz;    /* versions for compressed header */
  uint8_t flags;                 /* flags for header */
  int32_t ntbytes;               /* the number of uncompressed bytes */
  uint32_t nblocks;              /* number of total blocks in buffer */
  uint32_t leftover;             /* extra bytes at end of buffer */
  uint32_t *bstarts;             /* start pointers for each block */
  uint32_t typesize, blocksize, nbytes, ctbytes;

  _src = (uint8_t *)(src);
  _dest = (uint8_t *)(dest);

  /* Read the header block */
  version = _src[0];                         /* blosc format version */
  versionlz = _src[1];                       /* blosclz format version */
  flags = _src[2];                           /* flags */
  typesize = (uint32_t)_src[3];              /* typesize */
  _src += 4;
  nbytes = sw32(((uint32_t *)_src)[0]);      /* buffer size */
  blocksize = sw32(((uint32_t *)_src)[1]);   /* block size */
  ctbytes = sw32(((uint32_t *)_src)[2]);     /* compressed buffer size */

  _src += sizeof(int32_t)*3;
  bstarts = (uint32_t *)_src;
  /* Compute some params */
  /* Total blocks */
  nblocks = nbytes / blocksize;
  leftover = nbytes % blocksize;
  nblocks = (leftover>0)? nblocks+1: nblocks;
  _src += sizeof(int32_t)*nblocks;

  /* Check that we have enough space to decompress */
  if (nbytes > destsize) {
    return -1;
  }

  /* Populate parameters for decompression routines */
  params.compress = 0;
  params.clevel = 0;            /* specific for compression */
  params.flags = (int32_t)flags;
  params.typesize = typesize;
  params.blocksize = blocksize;
  params.ntbytes = 0;
  params.nbytes = nbytes;
  params.nblocks = nblocks;
  params.leftover = leftover;
  params.bstarts = bstarts;
  params.src = (uint8_t *)src;
  params.dest = (uint8_t *)dest;

  /* Check whether this buffer is memcpy'ed */
  if (flags & BLOSC_MEMCPYED) {
    if (((nbytes % L1) == 0) || (nthreads > 1)) {
      /* More effective with large buffers that are multiples of the
       cache size or multi-cores */
      ntbytes = do_job();
    }
    else {
      memcpy(dest, (uint8_t *)src+BLOSC_MAX_OVERHEAD, nbytes);
      ntbytes = nbytes;
    }
  }
  else {
    /* Do the actual decompression */
    ntbytes = do_job();
  }

  assert(ntbytes <= (int32_t)destsize);
  return ntbytes;
}
Exemplo n.º 10
0
static ERL_NIF_TERM do_job(ErlNifEnv* env, int argc,
			   const ERL_NIF_TERM argv[])
{
  state_t *state = NULL;
  ErlNifBinary input;
  size_t block_size;
  int is_eof;
  size_t input_size;
  char *input_data;
  rs_result res;
    
  if (!enif_get_resource(env, argv[0], state_r, (void *) &state))
    return enif_make_badarg(env);

  if (argc == 1) {
    is_eof = 1;
    input_size = 0;
    input_data = NULL;
  } else {
    if (!enif_inspect_iolist_as_binary(env, argv[1], &input))
      return enif_make_badarg(env);
    is_eof = 0;
    input_size = input.size;
    input_data = (char *) input.data;
  }

  block_size = MAX(state->in_size + input_size, RS_JOB_BLOCKSIZE);
  if (input_size) {
    state->in = realloc(state->in, state->in_size + input_size);
    memcpy(state->in + state->in_size, input_data, input_size);
  }
  state->in_size += input_size;
  state->out_size = 0;

  while (1) {
    state->out = realloc(state->out, state->out_size + block_size);
    rs_buffers_t buf = {.next_in = state->in,
			.avail_in = state->in_size,
			.eof_in = is_eof,
			.next_out = state->out + state->out_size,
			.avail_out = block_size};
    res = rs_job_iter(state->job, &buf);
    state->in_size = buf.avail_in;
    state->out_size += block_size - buf.avail_out;
    if (res == RS_BLOCKED) {
      if (buf.avail_in > 0) {
	state->in = realloc(state->in, buf.avail_in);
	memcpy(state->in, buf.next_in, buf.avail_in);
      }
      if (!is_eof)
	return mk_output(env, state);
    } else if (res == RS_DONE) {
      return mk_output(env, state);
    } else {
      return mk_error(env, res);
    }
  }
}

static ERL_NIF_TERM job_iter(ErlNifEnv* env, int argc,
			     const ERL_NIF_TERM argv[])
{
  return do_job(env, argc, argv);
}

static ERL_NIF_TERM job_done(ErlNifEnv* env, int argc,
			     const ERL_NIF_TERM argv[])
{
  return do_job(env, argc, argv);
}

static ErlNifFunc nif_funcs[] =
  {
    {"sig_init", 0, sig_init},
    {"loadsig_init", 0, loadsig_init},
    {"delta_init", 1, delta_init},
    {"patch_init", 1, patch_init},
    {"format_error_nif", 1, format_error},
    {"job_iter", 2, job_iter},
    {"job_done", 1, job_done}
  };

ERL_NIF_INIT(rsync, nif_funcs, load, NULL, NULL, NULL)
Exemplo n.º 11
0
//BACKWARD X      X  ;
void backward(int energy)
{
	printf("BACKWARD ");
	do_job(energy);
}
Exemplo n.º 12
0
//FRONT X      X  ;
void front(int energy)
{
	printf("FRONT ");
	do_job(energy);
}
Exemplo n.º 13
0
//RIGHT X      X  ;
void right(int energy)
{
	printf("RIGHT ");
	do_job(energy);
}
Exemplo n.º 14
0
//LEFT X      X  ;
void left(int energy)
{
	printf("LEFT ");
	do_job(energy);
}