Example #1
0
extern sfc_boundary_2_t sfc_boundary_2_get(uint32_t rank, uint32_t ncpu, sfc_key_t *fstkey, sfc_key_t *lstkey, uint32_t bits, sfc_curve_t ctype) {
    sfc_boundary_2_t dummy;
    sfc_key_t        key, shell[27];
    int              i, j;
    uint32_t         is_on_cpu;

    /* Aquire the memory for the structure */
    dummy = (sfc_boundary_2_t)malloc(sizeof(sfc_boundary_2_struct_t));
    if(dummy == NULL) {
        SID_exit_error("boundary structure", SID_ERROR_LOGIC);
        /*
io_logging_memfatal(log, "boundary structure");
return NULL;
        */
    }

    /* Generate the real boundaries (key arrays) */
    dummy->outer     = sfc_boundary_new(1, SFC_BOUNDARY_TYPE_OUTER, fstkey[rank], lstkey[rank], bits, ctype);
    dummy->num_inner = ncpu;
    dummy->inner     = sfc_boundary_new(ncpu, SFC_BOUNDARY_TYPE_INNER, fstkey[rank], lstkey[rank], bits, ctype);

    /* Now loop over all keys and put them in the right boundary array */
    for(key = fstkey[rank]; key <= lstkey[rank]; key++) {
        sfc_curve_getShell(ctype, key, shell, bits);
        for(i = 0; i < 27; i++) {
            is_on_cpu = local_localize_key(shell[i], ncpu, fstkey, lstkey);
            if(is_on_cpu != rank) {
                sfc_boundary_addKey(dummy->outer, shell[i]);
                sfc_boundary_addKey(dummy->inner + is_on_cpu, key);
            }
        }
    }

    return dummy;
}
Example #2
0
void
ahf_halos_sfc_gatherParts(HALO *halo)
{
	double centre[3];
	sfc_key_t centreKey;
	sfc_key_t shell[27];
	uint32_t bits;
	double gatherRad, gatherRad2;
	sfc_curve_t ctype;
	int i;

	/*--- INIT --------------------------------------------------------*/
	/* Do that once: Set the SFC type */
#	if (!defined WITH_MPI)
	ctype = global_info.ctype;
#	else
	ctype = global_info.loadbal->ctype;
#	endif
	/* Calculate/Copy the bounding box/centre positions */
	centre[0] = halo->pos.x;
	centre[1] = halo->pos.y;
	centre[2] = halo->pos.z;
   
	/* Compare to the squared gather radius so that no sqrt is needed */
	gatherRad  = halo->gatherRad;
	gatherRad2 = gatherRad*gatherRad;

	/*--- SETUP -------------------------------------------------------*/
	/* Now calculate the most suitable coarseness of the search grid */
	bits = local_getSuitableBits(halo, halo->gatherRad);
	/* Get the key of the cell containing the center */
	centreKey = sfc_curve_calcKey(ctype ,centre[0], centre[1],
	                              centre[2], bits);
	/* Get the shell around this cell */
	sfc_curve_getShell(ctype, centreKey, shell, bits);

	/*--- GATHERING ---------------------------------------------------*/
	/* Now loop over all possible cells and check which of their
	 * particles ought to be added to the halo. */
  
  if(bits == 1)
   {
    /* this loops over all cells inside the box */
    for (i=0; i<8; i++) {
      //if (local_checkCellDistance(i, centre, gatherRad, ctype,bits))
        local_checkAndAddParticles(i, halo, centre, gatherRad2, ctype, bits);
    }
   }
  else
   {
    /* this loops over all direct neighbouring cells */
    for (i=0; i<27; i++) {
      if (local_checkCellDistance(shell[i], centre, gatherRad, ctype,bits))
        local_checkAndAddParticles(shell[i], halo, centre, gatherRad2, ctype, bits);
    }
   }
    
    
	/*--- FINISHING ---------------------------------------------------*/
	/* Done we are */
#ifdef VERBOSE2
	fprintf(io.logfile,"%12ld\n", halo->npart);
	fflush(io.logfile);
#endif
  
	fflush(io.logfile);
	return;
}
Example #3
0
extern sfc_boundary_t sfc_boundary_get(sfc_boundary_type_t btype, sfc_key_t minkey, sfc_key_t maxkey, uint32_t bits, sfc_curve_t ctype) {
    sfc_boundary_t dummy;
    sfc_key_t      i;
    sfc_key_t      shell[27];
    int32_t        j;

    /* Sanity checks */
    if((btype != SFC_BOUNDARY_TYPE_INNER) && (btype != SFC_BOUNDARY_TYPE_OUTER)) {
        SID_exit_error("unsupported boundary type", SID_ERROR_LOGIC);
        /*
io_logging_fatal(log, "Unsupported boundary type: %s",
                 sfc_boundary_typestr(btype));
return NULL;
        */
    }

    /* Get the structure */
    dummy = (sfc_boundary_t)malloc(sizeof(sfc_boundary_struct_t));
    if(dummy == NULL) {
        SID_exit_error("boundary structure", SID_ERROR_LOGIC);
        /*
io_logging_memfatal(log, "boundary structure");
return NULL;
        */
    }

    /* Set general stuff */
    dummy->num    = 0;
    dummy->len    = (uint64_t)((maxkey - minkey) / UINT64_C(10));
    dummy->inc    = (uint32_t)(dummy->len / 5);
    dummy->minkey = minkey;
    dummy->maxkey = maxkey;
    dummy->btype  = btype;
    dummy->ctype  = ctype;
    dummy->bits   = bits;
    if(dummy->len < SFC_BOUNDARY_MIN_SIZE)
        dummy->len = SFC_BOUNDARY_MIN_SIZE;
    if(dummy->inc < SFC_BOUNDARY_MIN_INC)
        dummy->inc = SFC_BOUNDARY_MIN_INC;

    /* Get a first boundary array */
    dummy->bound = (sfc_key_t *)malloc(sizeof(sfc_key_t) * dummy->len);
    if(dummy->bound == NULL) {
        free(dummy);
        SID_exit_error("boundary key array", SID_ERROR_LOGIC);
        /*
io_logging_memfatal(log, "boundary key array");
return NULL;
*/
    }

    /* Get the boundary */
    switch(btype) {
        case SFC_BOUNDARY_TYPE_OUTER:
            /* Check all shell keys and add those not in the segment */
            for(i = minkey; i <= maxkey; i++) {
                sfc_curve_getShell(ctype, i, shell, bits);
                for(j = 0; j < 27; j++) {
                    if((shell[j] < minkey) || (shell[j] > maxkey))
                        sfc_boundary_addKey(dummy, shell[j]);
                }
            }
            break;
        case SFC_BOUNDARY_TYPE_INNER:
            /* Check the shell of all keys, if one of the shell keys
             * does not belong to the segment, add the shell center to
             * the boundary */
            for(i = minkey; i <= maxkey; i++) {
                sfc_curve_getShell(ctype, i, shell, bits);
                for(j = 0; j < 27; j++) {
                    if((shell[j] < minkey) || (shell[j] > maxkey)) {
                        sfc_boundary_addKey(dummy, i);
                        break;
                    }
                }
            }
            break;
    }

    return dummy;
}