Ejemplo n.º 1
0
s32 read_file(char *filepath, u8 **buffer, u32 *filesize){
	s32 Fd;
	int ret;

	if(buffer == NULL){
		printf("NULL Pointer\n");
		return -1;
	}

	Fd = ISFS_Open(filepath, ISFS_OPEN_READ);
	if (Fd < 0){
		//printf("\n   * ISFS_Open %s failed %d", filepath, Fd);
		//Pad_WaitButtons();
		return Fd;
	}

	fstats *status;
	status = allocate_memory(sizeof(fstats));
	if (status == NULL){
		printf("Out of memory for status\n");
		return -1;
	}
	
	ret = ISFS_GetFileStats(Fd, status);
	if (ret < 0){
		printf("ISFS_GetFileStats failed %d\n", ret);
		ISFS_Close(Fd);
		free(status);
		return -1;
	}
	
	*buffer = allocate_memory(status->file_length);
	if (*buffer == NULL){
		printf("Out of memory for buffer\n");
		ISFS_Close(Fd);
		free(status);
		return -1;
	}
		
	ret = ISFS_Read(Fd, *buffer, status->file_length);
	if (ret < 0){
		printf("ISFS_Read failed %d\n", ret);
		ISFS_Close(Fd);
		free(status);
		free(*buffer);
		return ret;
	}
	ISFS_Close(Fd);

	*filesize = status->file_length;
	free(status);

	return 0;
}
Ejemplo n.º 2
0
s32 getdir(char *path, dirent_t **ent, u32 *cnt){
	s32 res;
	u32 num = 0;

	int i, j, k;
	
	res = ISFS_ReadDir(path, NULL, &num);
	if(res != ISFS_OK){
		printf("Error: could not get dir entry count! (result: %d)\n", res);
		return -1;
	}

	char ebuf[ISFS_MAXPATH + 1];

	char *nbuf = (char *)allocate_memory((ISFS_MAXPATH + 1) * num);
	if(nbuf == NULL){
		printf("ERROR: could not allocate buffer for name list!\n");
		return -2;
	}

	res = ISFS_ReadDir(path, nbuf, &num);
	DCFlushRange(nbuf,13*num); //quick fix for cache problems?
	if(res != ISFS_OK){
		printf("ERROR: could not get name list! (result: %d)\n", res);
		free(nbuf);
		return -3;
	}
	
	*cnt = num;
	
	*ent = allocate_memory(sizeof(dirent_t) * num);
	if(*ent==NULL){
		printf("Error: could not allocate buffer\n");
		free(nbuf);
		return -4;
	}

	for(i = 0, k = 0; i < num; i++){	    
		for(j = 0; nbuf[k] != 0; j++, k++)
			ebuf[j] = nbuf[k];
		ebuf[j] = 0;
		k++;

		strcpy((*ent)[i].name, ebuf);
	}
	
	qsort(*ent, *cnt, sizeof(dirent_t), __FileCmp);
	
	free(nbuf);
	return 0;
}
Ejemplo n.º 3
0
inline
VectorDBase<T>::VectorDBase(Size s, T v)
{
    assert(s >= 0);
    allocate_memory(s);
    assignT(v);
}
Ejemplo n.º 4
0
//=============================================================
//                 GJointPlanar
//=============================================================
GJointPlanar::GJointPlanar()
{
	jointType = GJOINT_PLANAR;
	pCoordinates.push_back(&coordinates[0]);
	pCoordinates.push_back(&coordinates[1]);
	allocate_memory(2);
}
Ejemplo n.º 5
0
void read_rest_of_floating_point_number (agent* thisAgent) {
  /* --- at entry, current_char=="."; we read the "." and rest of number --- */
  store_and_advance(thisAgent);
  while (isdigit(thisAgent->current_char)) store_and_advance(thisAgent); /* string of digits */
  if ((thisAgent->current_char=='e')||(thisAgent->current_char=='E')) {
    store_and_advance(thisAgent);                             /* E */
    if ((thisAgent->current_char=='+')||(thisAgent->current_char=='-'))
      store_and_advance(thisAgent);                       /* optional leading + or - */
    while (isdigit(thisAgent->current_char)) store_and_advance(thisAgent); /* string of digits */
  }
  finish(thisAgent);

#ifdef __SC__
  if (strcmp("soar>",thisAgent->lexeme.string)) { /* if the lexeme doesn't equal "soar>" */
  	if (!(strncmp("soar>",thisAgent->lexeme.string,5))) { /* but the first 5 chars are "soar>" */
		/* then SIOW messed up so ignore the "soar>" */
	   buf = (char *)allocate_memory(thisAgent, (len=(strlen(thisAgent->lexeme.string)+1))*sizeof(char),STRING_MEM_USAGE);
	   for (i=0;i<=len;i++) {
	   	   buf[i] = thisAgent->lexeme.string[i];
	   }
	   for (i=5;i<=len;i++) {
	   	   thisAgent->lexeme.string[i-5] = buf[i];
	   }
	   free_memory_block_for_string(thisAgent, buf);
	}
  }
#endif
}
Ejemplo n.º 6
0
void enter_params()
{
	printf("Enter the number of instruction classes: ");
	scanf("%d", &nmbr_instr_classes);

    printf("Enter the frequency of the machine (MHz): ");
	scanf("%d", &freq);

	allocate_memory();

   	int i;
        for (i = 0;i<nmbr_instr_classes;i++)
        {
            int i_text = i + 1;
            printf("Enter CPI of class %d: ",(int)i_text);
            scanf("%d", &cpi[i]);

            printf("Enter instruction count of class %d (millions):",(int)i_text);
            scanf("%d", &count[i]);

            instruction_total += count[i];
            cycle_total += cpi[i]*count[i];
        }
	return;
}
Ejemplo n.º 7
0
int  SHMBase::connect_shared_memory( char mAllocate )
{
	bool available = is_IPC_memory_available();
 
	if (!available) 
	{
		if (mAllocate) {
			int result = allocate_memory( );
			if (result == -1)	{
				Dprintf("Cannot allocate shared memory!\n");
			}
			attach_memory( );
			fill_memory  ( );
			save_segment_id( );		
			return 1;
		}
	}
	 else  
	{
		attach_memory();	
		if (is_poiner_valid()==true)
			return 1;			
	}
	return 0;
}
Ejemplo n.º 8
0
int main() {
  int action;
  double *pointer;

  while(1) {
    show_menu();
    scanf("%d", &action);
    switch(action) {
      case 0:
        exit(0);
        break;
      case 1:
        pointer = allocate_memory();
        break;
      case 2:
        fill_memory(pointer);
        break;
      case 3:
        print_memory(pointer);
        break;
      case 4:
        free(pointer);
        break;
    }
  }
}
Ejemplo n.º 9
0
//=============================================================
//                 GJointRevolute
//=============================================================
GJointRevolute::GJointRevolute()
{
    jointType = GJOINT_REVOLUTE;
    axis = Vec3(0,0,1);							// default axis
    pCoordinates.push_back(&coordinate);		// set coordinate pointer
    allocate_memory(1);
}
Ejemplo n.º 10
0
int main (int argc, char *argv[])
{
        struct pe_vars v;
	long * msg_buffer;
	/*
	 * Initialize
	 */
	init_mpi(&v);
	check_usage(argc, argv, v.npes, v.me);
	print_header(v.me);

	if (v.me == 0) printf("Total processes = %d\n",v.npes);
	/*
	 * Allocate Memory
	 */
	msg_buffer = allocate_memory(v.me, &(v.win) );
	memset(msg_buffer, 0, MAX_MSG_SZ * ITERS_LARGE * sizeof(long));
	/*
	 * Time Put Message Rate
	 */
	benchmark(msg_buffer, v.me, v.pairs, v.nxtpe, v.win);
	/*
	 * Finalize
	 */
	MPI_Win_unlock_all(v.win);
	MPI_Win_free(&v.win); 	
	MPI_Free_mem(msg_buffer);

	MPI_Finalize();

	return EXIT_SUCCESS;
}
Ejemplo n.º 11
0
void *allocate_memory_and_zerofill (agent* thisAgent, size_t size, int usage_code) {
  void *p;

  p = allocate_memory (thisAgent, size, usage_code);
  memset (p, 0, size);
  return p;
}
Ejemplo n.º 12
0
/*
 * @brief Photographic tone-reproduction
 *
 * @param Y input luminance
 * @param L output tonemapped intensities
 * @param use_scales true: local version, false: global version of TMO
 * @param key maps log average luminance to this value (default: 0.18)
 * @param phi sharpening parameter (defaults to 1 - no sharpening)
 * @param num number of scales to use in computation (default: 8)
 * @param low size in pixels of smallest scale (should be kept at 1)
 * @param high size in pixels of largest scale (default 1.6^8 = 43)
 */
void tmo_reinhard02(
  unsigned int width, unsigned int height,
  const float *nY, float *nL, 
  bool use_scales, float key, float phi, 
  int num, int low, int high, bool temporal_coherent )
{
  const pfstmo::Array2D* Y = new pfstmo::Array2D(width, height, const_cast<float*>(nY));
  pfstmo::Array2D* L = new pfstmo::Array2D(width, height, nL);

  int x,y;

  ::key = key;
  ::phi = phi;
  ::range = num;
  ::scale_low = low;
  ::scale_high = high;
  ::use_scales = (use_scales) ? 1 : 0;
  ::temporal_coherent = temporal_coherent;

  cvts.xmax = Y->getCols();
  cvts.ymax = Y->getRows();

  sigma_0      = log (scale_low);
  sigma_1      = log (scale_high);

  compute_bessel();
  allocate_memory ();

  // reading image
  for( y=0 ; y<cvts.ymax ; y++ )
    for( x=0 ; x<cvts.xmax ; x++ )
      image[y][x][0] = (*Y)(x,y);

  copy_luminance();
  scale_to_midtone();

  if( use_scales )
  {
#ifdef APPROXIMATE
    build_pyramid(luminance, cvts.xmax, cvts.ymax);
#else
    compute_fourier_convolution();
#endif
  }

  tonemap_image();

  // saving image
  for( y=0 ; y<cvts.ymax ; y++ )
    for( x=0 ; x<cvts.xmax ; x++ )
      (*L)(x,y) = image[y][x][0];

//  print_parameter_settings();

  deallocate_memory();
  clean_pyramid();

  delete L;
  delete Y;
}
Ejemplo n.º 13
0
void start(){
	student *std=NULL;
	int counter, no_of_studnets, no_of_testcases;
	printf("Enter no.of testcases:");
	scanf("%d", &no_of_testcases);
	while (no_of_testcases > 0){
		printf("\n\nTestcase:\n\nEnter no of students:");
		scanf("%d", &no_of_studnets);
		std = (student *)malloc(no_of_studnets * sizeof(student));
		for (counter = 0; counter < no_of_studnets; counter++)
		{
			printf("\n\nEnter student-%d details:\n\n", counter);
			std[counter] = allocate_memory();
			printf("Enter Student ID:");
			scanf("%s", std[counter]->student_ID);
			if (is_student_new(std, counter) == 1){
				read_student_details(std[counter]);
			}
			else{
				printf("\n***** This Id already exist..****\n\n");
				counter--;
			}
		}
		check_student(std, no_of_studnets);
		no_of_testcases--;
	}
}
int main (int argc,char **argv)
{
  extern char *inputfile,*initfile,*outputfile;
  int input_array_int[10];
  double input_array[10];

  int error;
 
  error=MPI_Init (&argc, &argv);  //MPI INITIALIZE
  com=MPI_COMM_WORLD;
   
  if(error!=MPI_SUCCESS){
    printf("MPI could not be initialized.\n");
    exit(1);
  }

  MPI_Comm_size (com, &size);
  MPI_Comm_rank (com, &rank);

  if(argc != 4) usage();     //VERIFICATION OF INPUT FILES

  if (rank == 0)
    {
      initfile=argv[1];      //ASIGNATION
      inputfile=argv[2];     //OF FILE'S 
      outputfile=argv[3];    //NAMES
      
      create_remove_dir();   //REMOVE OLD outputfile AND CREATE A NEW ONE

      read_in(input_array_int,input_array);         //READ INITIAL CONDITIONS
    }

  MPI_Bcast(input_array_int, 2 , MPI_INT, 0 , com);  
  MPI_Bcast(input_array, 6 , MPI_DOUBLE, 0 , com);  

  Num_par = input_array_int[0];      //NUMBER OF PARTICLES IN THE SIMULATION
  INTEGRATOR = input_array_int[1];   //INTEGRATOR ELECTION
  
  t = input_array[0];                //TIMESTEP
  G = input_array[1];                //GRAVITATION CONSTANT
  w = input_array[2];                //STAR'S ROTATION 
  Num_archive   = input_array[3];    //NUMBER OUTPUT ARCHIVES
  Num_simulation= input_array[4];    //NUMBER OF INTEGRATION FOR ARCHIVE
  EPS = input_array[5];              //SOFTENING
  
  allocate_memory();                 //ALLOCATE THE MEMORY
  
  if (rank == 0) read_input();       //READ INITIAL POSITIONS AND VELOCITIES 

  Bcast_part_struct(0);  //MASTER MAKE A BROADCAST OF INITIAL POSITIONS AND VELOCITIES

  emulator();            //SIMULATION 

  free_memory();         //FREE THE MEMORY

  error=MPI_Finalize();  //END OF MPI

  return error;
}
Ejemplo n.º 15
0
/*-------------------------------------------------------------------------*/
void       *
malloc(ULONG length)
{
	void       *caller_addr = (void *) *((ULONG *) & length - 1);

	return (allocate_memory(length, caller_addr));

}				/* malloc */
Ejemplo n.º 16
0
int main (int argc, char *argv[])
{
	int i, ret;
	int size, is_server;
	double t_start = 0.0, t_end = 0.0;
	double latency;
	struct iovec s_iov, r_iov;
	uintptr_t peer_addr;
	int peer_pid;
	
	if (allocate_memory(&s_buf, &r_buf)) {
		/* Error allocating memory */
		exit(-1);
	}
	
	is_server = (argc == 1);
	if (is_server) {
		fprintf(stderr, "server ready: %d, %p\n", getpid(), r_buf);
		while (1);
	}
	
	peer_pid = atoi(argv[1]);
	peer_addr = (uintptr_t) strtol(argv[2], NULL, 16);
	
	s_iov.iov_base = s_buf;
	r_iov.iov_base = (void *) peer_addr;
	
	print_header();
	
	/* Latency test */
	for(size = 0; size <= MAX_MSG_SIZE; size = (size ? size * 2 : 1)) {
		touch_data(s_buf, r_buf, size);

		if(size > LARGE_MESSAGE_SIZE) {
			loop = LOOP_LARGE;
			skip = SKIP_LARGE;
		}

		for(i = 0; i < loop + skip; i++) {
			if(i == skip)
				t_start = TIME();

			s_iov.iov_len = r_iov.iov_len = size;
			ret = process_vm_writev(peer_pid,
						&s_iov, 1, 
						&r_iov, 1, 0);
			if (ret != size) {
				fprintf(stderr, "process_vm_writev failed: %d\n", ret);
				exit(-1);
			}
		}
		t_end = TIME();
		latency = (1.0 * (t_end-t_start)) / loop;
		fprintf(stderr, "%-*d%*.*f\n", 10, size, FIELD_WIDTH,
			FLOAT_PRECISION, latency);
	}
	return 0;
}
enum plugin_status plugin_start(const void* void_parameter)
{
    bool found;
    bool its_a_dir;
    
    /* This is a viewer, so a parameter must have been specified */
    if (void_parameter == NULL) {
        rb->splash(HZ*2, "No parameter specified!");
        return PLUGIN_ERROR;
    }
    char *parameter = (char*)void_parameter;
    DEBUGF("Trying to append '%s' to the default link file '%s'...\n",
            parameter, SHORTCUTS_FILENAME);

    allocate_memory(&memory_buf, &memory_bufsize);

    /* Determine if it's a file or a directory. First check
     * if it's a dir and then file (not vice versa) since
     * open() can also open a dir */
    found = true;
    if (rb->dir_exists(parameter)) {
        its_a_dir = true;
    } else if (rb->file_exists(parameter)) {
        its_a_dir = false;
    } else {
        found = false;
    }
    /* now we know if it's a file or a directory
     * (or something went wrong) */

    if (!found) {
        /* Something's gone properly pear shaped -
         * we couldn't even find the entry */
        rb->splashf(HZ*2, "File/Dir not found: %s", parameter);
        return PLUGIN_ERROR;
    }

    DEBUGF("'%s' is a %s\n", parameter, (its_a_dir ? "dir" : "file"));

    if (!load_sc_file(&sc_file, SHORTCUTS_FILENAME, false,
                memory_buf, memory_bufsize)) {
        DEBUGF("Couldn't load '%s'\n", SHORTCUTS_FILENAME);
        return PLUGIN_ERROR;
    }
    
    if (!append_entry_to_file(&sc_file, parameter, its_a_dir)) {
        DEBUGF("Couldn't append entry (too many entries?)\n");
        return PLUGIN_ERROR;
    }
    
    if (!dump_sc_file(&sc_file, SHORTCUTS_FILENAME)) {
        DEBUGF("Couldn't write shortcuts to '%s'\n", SHORTCUTS_FILENAME);
        return PLUGIN_ERROR;
    }

    return PLUGIN_OK;
}
Ejemplo n.º 18
0
/* Allocate an input node for a given input pin */
static MuxInputNode * create_input_node(int in_pin)
{
    MuxInputNode *node = (MuxInputNode *) allocate_memory(sizeof(MuxInputNode));

    node->in_pin = in_pin;
    node->next = NULL;

    return node;
}
Ejemplo n.º 19
0
/*-------------------------------------------------------------------------*/
void       *
realloc(void *ptr, ULONG new_length)
{
	void       *caller_addr = (void *) *((ULONG *) & ptr - 1);
	mem_type   *temp;
	ULONG       alloc_length;
	void       *cnew;

	if (new_length == 0) {
		if (ptr)
			free(ptr);
		return (NULL);
	}
	if (ptr == NULL)
		return (allocate_memory(new_length, caller_addr));

	temp = (mem_type *) ((char *) ptr - sizeof (struct mem_hdr));

	if (temp->hdr.check_mark != USED_MARKER) {
		message("REALLOC - corrupt malloc list");
		*(ULONG *) 1 = 1L;
	}
	alloc_length = temp->hdr.chunk_size - sizeof (mem_type);

	if (new_length <= alloc_length) {
		/* check data length integrity */
		if (temp->data[temp->hdr.used_length] != EOD_MARKER) {
			message("FREE - end of data corrupted");
			*(ULONG *) 1 = 1L;
		}
		/* update the info */
		temp->hdr.used_length = new_length;
		temp->data[new_length] = EOD_MARKER;
	} else {
		/* we need a new chunk */
		cnew = allocate_memory(new_length, caller_addr);
		(void) memcpy(cnew, ptr, temp->hdr.used_length);
		free(ptr);
		ptr = cnew;
	}

	return (ptr);

}				/* realloc */
Ejemplo n.º 20
0
/*Run PUT with Fence */
void run_put_with_fence(int rank, WINDOW type)
{
    double t; 
    int size, i, j;
    MPI_Aint disp = 0;
    MPI_Win     win;

    int window_size = WINDOW_SIZE_LARGE;
    for (size = 1; size <= MAX_SIZE; size = size * 2) {
        allocate_memory(rank, sbuf_original, rbuf_original, &sbuf, &rbuf, &rbuf, size*window_size, type, &win);

#if MPI_VERSION >= 3
        if (type == WIN_DYNAMIC) {
            disp = disp_remote;
        }
#endif

        if(size > LARGE_MESSAGE_SIZE) {
            loop = LOOP_LARGE;
            skip = SKIP_LARGE;
        }

        MPI_CHECK(MPI_Barrier(MPI_COMM_WORLD));

        if(rank == 0) {
            for (i = 0; i < skip + loop; i++) {
                if (i == skip) {
                    t_start = MPI_Wtime ();
                }
                MPI_CHECK(MPI_Win_fence(0, win));
                for(j = 0; j < window_size; j++) {
                    MPI_CHECK(MPI_Put(sbuf+(j*size), size, MPI_CHAR, 1, disp + (j * size), size, MPI_CHAR,
                            win));
                }
                MPI_CHECK(MPI_Win_fence(0, win));
            }
            t_end = MPI_Wtime ();
            t = t_end - t_start;
        } else {
            for (i = 0; i < skip + loop; i++) {
                MPI_CHECK(MPI_Win_fence(0, win));
                for(j = 0; j < window_size; j++) {
                    MPI_CHECK(MPI_Put(sbuf+(j*size), size, MPI_CHAR, 0, disp + (j * size), size, MPI_CHAR,
                            win));
                }
                MPI_CHECK(MPI_Win_fence(0, win));
            }
        }

        MPI_CHECK(MPI_Barrier(MPI_COMM_WORLD));

        print_bibw(rank, size, t);

        free_memory (sbuf, rbuf, win, rank);
    }
}
Ejemplo n.º 21
0
growable_string make_blank_growable_string (agent* thisAgent) {
  growable_string gs;

  gs = allocate_memory (thisAgent, 2*sizeof(int *) + INITIAL_GROWABLE_STRING_SIZE,
                        STRING_MEM_USAGE);
  memsize_of_growable_string(gs) = INITIAL_GROWABLE_STRING_SIZE;
  length_of_growable_string(gs) = 0;
  *(text_of_growable_string(gs)) = 0;
  return gs;
}
Ejemplo n.º 22
0
char *make_memory_block_for_string (agent* thisAgent, char const*s) {
  char *p;
  size_t size;

  size = strlen(s)+1; /* plus one for trailing null character */
  p = static_cast<char *>(allocate_memory (thisAgent, size, STRING_MEM_USAGE));
  strncpy(p,s,size);
  p[size-1] = 0; /* ensure null termination */
  return p;
}
Ejemplo n.º 23
0
/* Construct a tune which plays the tones of the supplied tune in the reverse order. */
static const struct tone_entry *invert_tune (const struct tone_entry *tune) {
   struct tone_entry *enut = NULL;
   while (tune) {
      struct tone_entry *tone = allocate_memory(sizeof(*tone));
      *tone = *tune;
      tone->next = enut;
      enut = tone;
      tune = tune->next;
   }
   return enut;
}
Ejemplo n.º 24
0
BellmanFordResult *bellmanFord(Graph *graph, int source){
    BellmanFordResult *bellman_ford_result;
    bellman_ford_result = allocate_memory(graph->numbers_nodes);
    initialize(bellman_ford_result, graph->numbers_nodes, source);
    for(int quantity = 1; quantity <= graph->numbers_nodes - 1; quantity++)
        for(int i = 0; i < graph->numbers_nodes; i++)
            for(int j = 0; j < graph->numbers_nodes; j++)
                relax(bellman_ford_result, graph, i, j);
    verify_negative_cycle(bellman_ford_result, graph);
    return bellman_ford_result;
}; 
Ejemplo n.º 25
0
int main(int argc, char** argv)
{
    int ret = EXIT_SUCCESS;

    /* Initialize param struct to zero */
    memset(&P, 0, sizeof(P));

    if (!parse_input(argc, argv)) {
        return EXIT_FAILURE;
    }

    /* Initialize parameters corresponding to YUV-format */
    setup_param();

    if (!sdl_init()) {
        return EXIT_FAILURE;
    }

    if (!open_input()) {
        return EXIT_FAILURE;
    }

    if (!allocate_memory()) {
        ret = EXIT_FAILURE;
        goto cleanup;
    }

    /* Lets do some basic consistency check on input */
    check_input();

    /* send event to display first frame */
    event.type = SDL_KEYDOWN;
    event.key.keysym.sym = SDLK_RIGHT;
    SDL_PushEvent(&event);

    /* while true */
    event_loop();

cleanup:
    destroy_message_queue();
    SDL_FreeYUVOverlay(my_overlay);
    free(P.raw);
    free(P.y_data);
    free(P.cb_data);
    free(P.cr_data);
    if (fd) {
        fclose(fd);
    }
    if (P.fd2) {
        fclose(P.fd2);
    }

    return ret;
}
Ejemplo n.º 26
0
/*Run ACC with Fence */
void run_acc_with_fence(int rank, WINDOW type)
{
    int size, i;
    MPI_Aint disp = 0;
    MPI_Win     win;


    for (size = 0; size <= MAX_SIZE; size = (size ? size * 2 : 1)) {
        allocate_memory(rank, sbuf_original, rbuf_original, &sbuf, &rbuf, &sbuf, size, type, &win);

#if MPI_VERSION >= 3
        if (type == WIN_DYNAMIC) {
            disp = disp_remote;
        }
#endif

        if(size > LARGE_MESSAGE_SIZE) {
            loop = LOOP_LARGE;
            skip = SKIP_LARGE;
        }

        MPI_CHECK(MPI_Barrier(MPI_COMM_WORLD));

        if(rank == 0) {
            for (i = 0; i < skip + loop; i++) {
                if (i == skip) {
                    t_start = MPI_Wtime ();
                }
                MPI_CHECK(MPI_Win_fence(0, win));
                MPI_CHECK(MPI_Accumulate(sbuf, size, MPI_CHAR, 1, disp, size, MPI_CHAR, MPI_SUM, win));
                MPI_CHECK(MPI_Win_fence(0, win));
                MPI_CHECK(MPI_Win_fence(0, win));
            }
            t_end = MPI_Wtime ();
        } else {
            for (i = 0; i < skip + loop; i++) {
                MPI_CHECK(MPI_Win_fence(0, win));
                MPI_CHECK(MPI_Win_fence(0, win));
                MPI_CHECK(MPI_Accumulate(sbuf, size, MPI_CHAR, 0, disp, size, MPI_CHAR, MPI_SUM, win));
                MPI_CHECK(MPI_Win_fence(0, win));
            }
        }

        MPI_CHECK(MPI_Barrier(MPI_COMM_WORLD));

        if (rank == 0) {
            fprintf(stdout, "%-*d%*.*f\n", 10, size, FIELD_WIDTH,
                    FLOAT_PRECISION, (t_end - t_start) * 1.0e6 / loop / 2);
            fflush(stdout);
        }

        free_memory (sbuf, rbuf, win, rank);
    }
}
Ejemplo n.º 27
0
int main(int argc, char *argv[])
{
	int ret;
	char mygroup[FILENAME_MAX], mytaskfile[FILENAME_MAX];
	char *mygroup_p, *script_pid_p, *test_num_p, *chunk_size_p;
	char *num_chunks_p;
	struct sigaction newaction1, newaction2, oldaction1, oldaction2;

	/* Capture variables from the script environment */
	test_num_p = getenv("TEST_NUM");
	mygroup_p = getenv("MYGROUP");
	script_pid_p = getenv("SCRIPT_PID");
	chunk_size_p = getenv("CHUNK_SIZE");
	num_chunks_p	= getenv("NUM_CHUNKS");

	if (test_num_p != NULL && mygroup_p != NULL && script_pid_p != NULL &&
	    chunk_size_p != NULL && num_chunks_p != NULL) {
		scriptpid       = atoi(script_pid_p);
		test_num        = atoi(test_num_p);
		chunk_size	= atoi(chunk_size_p);
		num_of_chunks	= atoi(num_chunks_p);
		sprintf(mygroup,"%s", mygroup_p);
	} else {
		tst_brkm(TBROK, cleanup,
		    "invalid parameters recieved from script\n");
	}

	/* XXX (garrcoop): this section really needs error handling. */

	/* Signal handling for SIGUSR1 recieved from script */
	sigemptyset(&newaction1.sa_mask);
	newaction1.sa_handler = signal_handler_sigusr1;
	newaction1.sa_flags=0;
	sigaction(SIGUSR1, &newaction1, &oldaction1);

	/* Signal handling for SIGUSR2 recieved from script */
	sigemptyset(&newaction2.sa_mask);
	newaction2.sa_handler = signal_handler_sigusr2;
	newaction2.sa_flags = 0;
	sigaction(SIGUSR2, &newaction2, &oldaction2);


	sprintf(mytaskfile, "%s", mygroup);
	strcat (mytaskfile,"/tasks");
	/* Assign the task to it's group */
	write_to_file (mytaskfile, "a", getpid());    /* Assign the task to it's group*/

	ret = allocate_memory();	/*should i check ret?*/

	cleanup();

	tst_exit();
}
Ejemplo n.º 28
0
/*-------------------------------------------------------------------------*/
void       *
calloc(ULONG nelem, ULONG length)
{
	void       *caller_addr = (void *) *((ULONG *) & nelem - 1);
	register void *temp;

	length *= nelem;
	temp = allocate_memory(length, caller_addr);
	(void) memset(temp, 0, length);
	return (temp);

}				/* calloc */
Ejemplo n.º 29
0
//int Lattice::init(double *agrid, double* offset, int halo_size, size_t dim) {
int Lattice::init(double *agrid, double* offset, int halo_size, size_t dim) {
    this->dim=dim;

    /* determine the number of local lattice nodes */
    for (int d=0; d<3; d++) {
        this->agrid[d] = agrid[d];
        this->global_grid[d] = (int)dround(box_l[d]/agrid[d]);
        this->offset[d]=offset[d];
        this->local_index_offset[d]=(int) ceil((my_left[d]-this->offset[d])/this->agrid[d]);
        this->local_offset[d] = this->offset[d] +
            this->local_index_offset[d]*this->agrid[d];
        this->grid[d] = (int) ceil ( ( my_right[d] - this->local_offset[d]-ROUND_ERROR_PREC )
                                     / this->agrid[d]);
    }

    // sanity checks
    for (int dir=0;dir<3;dir++) {
      // check if local_box_l is compatible with lattice spacing
      if (fabs(local_box_l[dir]-this->grid[dir]*agrid[dir]) > ROUND_ERROR_PREC*box_l[dir]) {
        char *errtxt = runtime_error(256);
        ERROR_SPRINTF(errtxt, \
                      "{097 Lattice spacing agrid[%d]=%f " \
                      "is incompatible with local_box_l[%d]=%f " \
                      "(box_l[%d]=%f node_grid[%d]=%d)} ",       \
                      dir, agrid[dir], \
                      dir, local_box_l[dir], \
                      dir, box_l[dir], \
                      dir, node_grid[dir]);
      }
    }

    this->element_size = this->dim*sizeof(double);

    LATTICE_TRACE(fprintf(stderr,"%d: box_l (%.3f,%.3f,%.3f) grid (%d,%d,%d) node_neighbors (%d,%d,%d,%d,%d,%d)\n",this_node,local_box_l[0],local_box_l[1],local_box_l[2],this->grid[0],this->grid[1],this->grid[2],node_neighbors[0],node_neighbors[1],node_neighbors[2],node_neighbors[3],node_neighbors[4],node_neighbors[5]));

    this->halo_size = halo_size;
    /* determine the number of total nodes including halo */
    this->halo_grid[0] = this->grid[0] + 2*halo_size ;
    this->halo_grid[1] = this->grid[1] + 2*halo_size ;
    this->halo_grid[2] = this->grid[2] + 2*halo_size ;

    this->grid_volume = this->grid[0]*this->grid[1]*this->grid[2] ;
    this->halo_grid_volume = this->halo_grid[0]*this->halo_grid[1]*this->halo_grid[2] ;
    this->halo_grid_surface = this->halo_grid_volume - this->grid_volume ;
    this->halo_offset = get_linear_index(halo_size,halo_size,halo_size,this->halo_grid) ;

    this->interpolation_type = INTERPOLATION_LINEAR;

    allocate_memory();
    return ES_OK;

}
Ejemplo n.º 30
0
void signal_handler_sigusr2(int signal)
{
	int i;
	for (i = 0; i < num_of_chunks; ++i)
		free(array_of_chunks[i]);
	free(array_of_chunks);
	if (test_num == 4) {
		/* Allocate different amount of memory for second step */
		chunk_size = 5242880;	/* 5 MB chunks */
		num_of_chunks = 15;
	}
	allocate_memory();
}