Example #1
0
//dump_ppm wrapper
int syn_dump_ppm(
    const char* fname,
    int width,
    int depth,
    const svOpenArrayHandle red,
    const svOpenArrayHandle green,
    const svOpenArrayHandle blue)
{

  int i;
  unsigned  char  *red_arry_ptr;
  unsigned  char  *green_arry_ptr;
  unsigned  char  *blue_arry_ptr;

  red_arry_ptr    = malloc((width*depth)*sizeof(unsigned char));
  green_arry_ptr  = malloc((width*depth)*sizeof(unsigned char));
  blue_arry_ptr   = malloc((width*depth)*sizeof(unsigned char));

  //Convert from svOpenArrayHandle type to unsigned char type
  for (i= svLeft(red,1); i <= svRight(red,1); i++) {
      red_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(red, i);
  }
  
  for (i= svLeft(green,1); i <= svRight(green,1); i++) {
      green_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(green, i);
  }

  for (i= svLeft(blue,1); i <= svRight(blue,1); i++) {
      blue_arry_ptr[i] = *(unsigned char*)svGetArrElemPtr1(blue, i);
  }


  return  dump_ppm(
                    fname,
                    width,
                    depth,
                    red_arry_ptr,
                    green_arry_ptr,
                    blue_arry_ptr
                  );
}
Example #2
0
int main(int argc, char *argv[]) {
  char *pendulumdatapath = "data_pendulum";
  char *dumppath = NULL;
  
  for (int i = 1; i < argc; i++) {
    if (argcmpass("--pendulum|-p", argc, argv, &i, &pendulumdatapath)) ;
    else if (argcmpass("--datafilepath|-d", argc, argv, &i, &datafilepath)) ;
    else if (argcmpass("--dump|-D", argc, argv, &i, &dumppath)) ;
    else if (ARGCMP("--whitebg", i)) {
      whitebg = 1;
    }
    else if (ARGCMP("--no-show-normal-lines", i)) show_normal_lines = false;
    else if (argcmpassdouble("--l1", argc, argv, &i, &l1)) ;
    else if (argcmpassdouble("--l2b", argc, argv, &i, &l2b)) ;
    else fprintf(stderr, "warning: Unknown argument ignored: \"%s\"\n", argv[i]);
  }
  
  if (l1 <= 0 || l2b <= 0) {
    fprintf(stderr, "l1 and l2b must be >0\n");
    exit(1);
  }
  
  // x11 things
  sf = createSHMSurface(100, 100, 500, 500);
  
  int in_fd = -1;
  if (dumppath == NULL) {
    in_fd = inotify_init();
    if (in_fd == -1) {
      fprintf(stderr, "can't create inotify fd: %s\n", strerror(errno));
      exit(1);
    }
    int in_watch = inotify_add_watch(in_fd, datafilepath, IN_CLOSE_WRITE);
    if (in_watch == -1) {
      fprintf(stderr, "can't create inotify watch: %s\n", strerror(errno));
      exit(1);
    }
  }
  
  run();
  
  if (dumppath != NULL) {
    int fd = open(dumppath, O_WRONLY|O_CREAT|O_TRUNC, 0777);
    if (fd == -1) {
      fprintf(stderr, "can't open \"%s\" for writing: %s\n", dumppath, strerror(errno));
      exit(1);
    }
    dump_ppm(fd, sf);
    close(fd);
    return 0;
  }
  
  while (1) {
    size_t evt_size = sizeof(struct inotify_event)+NAME_MAX+1;
    struct inotify_event *evt = alloca(evt_size);
    int readres = read(in_fd, evt, evt_size);
    if (readres == 0) {
      fprintf(stderr, "inotify EOF\n");
      exit(1);
    }
    if (readres == -1) {
      fprintf(stderr, "inotify read error: %s\n", strerror(errno));
      exit(1);
    }
    // we ignore the actual inotify event – there's only one thing it could
    // plausibly be, and if we're wrong, we just run one more iteration
    run();
  }
}
static void process_image(const void *p, int size)
{
    int i, newi, newsize=0;
    struct timespec frame_time;
    int y_temp, y2_temp, u_temp, v_temp;
    unsigned char *pptr = (unsigned char *)p;

    // record when process was called
    clock_gettime(CLOCK_REALTIME, &frame_time);    

    framecnt++;
    printf("frame %d: ", framecnt);

    // This just dumps the frame to a file now, but you could replace with whatever image
    // processing you wish.
    //

    if(fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_GREY)
    {
        printf("Dump graymap as-is size %d\n", size);
        dump_pgm(p, size, framecnt, &frame_time);
    }

    else if(fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_YUYV)
    {

#if defined(COLOR_CONVERT)
        printf("Dump YUYV converted to RGB size %d\n", size);
       
        // Pixels are YU and YV alternating, so YUYV which is 4 bytes
        // We want RGB, so RGBRGB which is 6 bytes
        //
        for(i=0, newi=0; i<size; i=i+4, newi=newi+6)
        {
            y_temp=(int)pptr[i]; u_temp=(int)pptr[i+1]; y2_temp=(int)pptr[i+2]; v_temp=(int)pptr[i+3];
            yuv2rgb(y_temp, u_temp, v_temp, &bigbuffer[newi], &bigbuffer[newi+1], &bigbuffer[newi+2]);
            yuv2rgb(y2_temp, u_temp, v_temp, &bigbuffer[newi+3], &bigbuffer[newi+4], &bigbuffer[newi+5]);
        }

        dump_ppm(bigbuffer, ((size*6)/4), framecnt, &frame_time);
#else
        printf("Dump YUYV converted to YY size %d\n", size);
       
        // Pixels are YU and YV alternating, so YUYV which is 4 bytes
        // We want Y, so YY which is 2 bytes
        //
        for(i=0, newi=0; i<size; i=i+4, newi=newi+2)
        {
            // Y1=first byte and Y2=third byte
            bigbuffer[newi]=pptr[i];
            bigbuffer[newi+1]=pptr[i+2];
        }

        dump_pgm(bigbuffer, (size/2), framecnt, &frame_time);
#endif

    }

    else if(fmt.fmt.pix.pixelformat == V4L2_PIX_FMT_RGB24)
    {
        printf("Dump RGB as-is size %d\n", size);
        dump_ppm(p, size, framecnt, &frame_time);
    }
    else
    {
        printf("ERROR - unknown dump format\n");
    }

    fflush(stderr);
    //fprintf(stderr, ".");
    fflush(stdout);
}
int main(int argc, char *argv[])
{
  MPI_Status status;
  int i,j, num, rank, size, nbslaves;
  char inputstr [100],outstr [100];

  /* Start up MPI */

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  nbslaves = size -1;

  printf("nbslave %d \n",size);

  if (rank == 0) {

    int res[NY];
    int k;
    int count_fini;
    int *curren_line = (int *)malloc(nbslaves*sizeof(int));
    //init current_ligne
    int m;
    for(m=0;m<nbslaves;m++){
        curren_line[m]=m;
    }



    /* Begin User Program  - the master */

   /*
   for(i = -MAXX; i <= MAXX; i+=nbslaves) {
      for(k=1;k<=nbslaves;k++){
            if(i+k-1>=MAXX)
                break;
        MPI_Recv(&res, NY, MPI_INT, k, DATATAG, MPI_COMM_WORLD, &status);
        memcpy(cases[i+MAXX+k-1], res, NY*sizeof(int));

      }
    }*/
    count_fini=0;
    while(1){
        MPI_Recv(&res, NY, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
        //distinguish type of the message


        if(status.MPI_TAG==DATATAG+1){
        //finish
            printf("souce:%d\n",status.MPI_SOURCE);
            printf("tag:%d\n",status.MPI_TAG);
            count_fini++;
            if(count_fini==nbslaves)
                break;

        }
        if(status.MPI_TAG==DATATAG){
            //status.MPI_SOURCE
            memcpy(cases[curren_line[status.MPI_SOURCE-1]], res, NY*sizeof(int));
            curren_line[status.MPI_SOURCE-1]+=nbslaves;
        }
    }

    dump_ppm("mandel-ligne.ppm", cases);
    printf("Fini.\n");
  }

  else {

    /* On est l'un des fils */
    double x, y;
    int i, j, res, rc;
    int res_Y[NY];
    for(i = -MAXX+rank-1; i <= MAXX; i=i+nbslaves) {

      for(j = -MAXY; j <= MAXY; j++) {
            x = 2 * i / (double)MAXX;
            y = 1.5 * j / (double)MAXY;
            res_Y[j+MAXY] = mandel(x, y);

      }
         MPI_Send(&res_Y, NY , MPI_INT, 0, DATATAG, MPI_COMM_WORLD);
    }
    //indicate this  is the last message of the slave
    res=1;
    MPI_Send(&res_Y, NY , MPI_INT, 0, DATATAG+1, MPI_COMM_WORLD);
  }

  MPI_Finalize();
  return 0;
}
Example #5
0
int
main(int argc, char **argv)
{
    int tid;
    int parent;

    struct pvmhostinfo *hostp;
    int nhost, narch;

    tid = pvm_mytid();
    if(tid < 0) pvm_ferror("pvm_mytid", 1);

    parent = pvm_parent();

    if(parent == PvmNoParent || parent == PvmParentNotSet) {
        /* Processus pere */
        int nchildren, children[MAXCHILDREN];
        int i, j, res, rc;
      int bytes, tag, from_tid;


    /* Ask PVM for information about the virtual machine, and display
       it to the user. 
    */
    
        pvm_config(&nhost, &narch, &hostp);
        printf("I found the following %d hosts...\n",nhost);
		
		
        for (i = 0; i < nhost; i++)
          printf("%d. %s \t(%s)\n",i,hostp[i].hi_name,hostp[i].hi_arch);



        rc = pvm_spawn("pvm_mandel", NULL, PvmTaskDefault, NULL, 
                       NUMCHILDREN, children);
        if(rc < 0) pvm_ferror("pvm_spawn", 1);
        printf("%d enfants\n", rc);
        nchildren = 0;
        for(i = 0; i < NUMCHILDREN; i++) {
            printf("Enfant %d, tid = %d\n", i, children[i]);
            if(children[i] >= 0)
                nchildren++;
            if(nchildren < 1)
                pvm_ferror("Pas d'enfants", 0);
        }
        for(i = -MAXX; i <= MAXX; i++) {
            for(j = -MAXY; j <= MAXY; j++) {
               rc = pvm_recv(-1,-1);

              if (rc < 0) {
                printf("An error occurred when trying to receive a message.\n");
                break;
              }

      /* Find out who this message is from, and how big it is. */

               rc = pvm_bufinfo(rc,&bytes,&tag,&from_tid);

               /* printf("received message from %s of %d bytes, tag %d\n",
                  get_host_by_tid(hostp,nhost,from_tid), bytes, tag);
               */

                rc = pvm_upkint(&res, 1, 1);
                if(rc < 0) pvm_ferror("pvm_upkint", 1);
                cases[i + MAXX][j + MAXY] = res;
            }
        }
        dump_ppm("mandel.ppm", cases);
        printf("Fini.\n");
        pvm_exit();
        exit(0);
    } else if(parent >= 0) {
        /* On est l'un des fils */
        double x, y;
        int i, j, res, rc;
        printf("Fils: %d\n", tid);
        for(i = -MAXX; i <= MAXX; i++) {
            for(j = -MAXY; j <= MAXY; j++) {
                x = 2 * i / (double)MAXX;
                y = 1.5 * j / (double)MAXY;
                res = mandel(x, y);
                rc = pvm_initsend(PvmDataDefault);
                if(rc < 0) pvm_ferror("pvm_initsend", 1);
                rc = pvm_pkint(&res, 1, 1);
                if(rc < 0) pvm_ferror("pvm_pkint", 1);
                rc = pvm_send(parent, 0);
                if(rc < 0) pvm_ferror("pvm_send", 1);
            }
        }
        printf("Fils %d termine.\n", tid);
        pvm_exit();
        exit(0);
    } else
        pvm_ferror("pvm_parent", 1);

    assert(0);
}