Exemplo n.º 1
0
void SpringEmbedderFRExact::cool(double &tx, double &ty, int &cF)
{
	switch(m_coolingFunction) {
		case cfFactor:
			tx *= m_coolFactor_x;
			ty *= m_coolFactor_y;
			break;

		case cfLogarithmic:
			tx = m_txNull / mylog2(cF);
			ty = m_tyNull / mylog2(cF);
			cF++;
			break;
	}
}
Exemplo n.º 2
0
// TODO: Remove all this and replace with a custom format that is sent to vu1 for
// transformation, lighting and being able to deal with other prim types!
MF_API void MFBegin(uint32 vertexCount)
{
	MFCALLSTACK;

	packet_reset(&packet);
	beginCount = vertexCount;
	currentVert = 0;

	MFMat_Standard_Data *pData = (MFMat_Standard_Data*)pSetMaterial->pInstanceData;
	MFTexture *pTexture = pData->pTextures[pData->diffuseMapIndex];
	width = pTexture->pTemplateData->pSurfaces[0].width;
	height = pTexture->pTemplateData->pSurfaces[0].height;

	int tw = mylog2(width);
	int th = mylog2(height);

	int num = vertexCount*2 + 9;

	packet_append_64(&packet, DMA_SET_TAG(num, 0, DMA_TAG_END, 0, 0, 0));
	packet_append_64(&packet, 0);

	packet_append_64(&packet, GIF_SET_TAG(num-1, 1, 0, 0, 0, 1 ));
	packet_append_64(&packet, GIF_AD);

	/* GIF_SET_TEX0(tex base, tex width, tex psm, width, height, texcure alpha component, texture function, CLUT stuff */
	packet_append_64(&packet, GIF_SET_TEX0( tex_addr>>8,  width >> 6, 0,tw,th,1,1,0,0,0,0,0));
	packet_append_64(&packet, GIF_REG_TEX0_1);

	packet_append_64(&packet, GIF_SET_TEX1(1, 0, 1, 1, 0, 0, 0));
	packet_append_64(&packet, GIF_REG_TEX1_1);

	packet_append_64(&packet, GIF_SET_TEXA(0, 1, 255));
	packet_append_64(&packet, GIF_REG_TEXA);

	packet_append_64(&packet, GIF_SET_CLAMP(0, 0, 0, 0, 0, 0));
	packet_append_64(&packet, GIF_REG_CLAMP_1);

	float one = 1.0f; /* cludgy way to obtain 1.0f as a u32 */
	packet_append_64(&packet, GIF_SET_RGBAQ( r, g, b, a, *((int*)(&one)) )  );
	packet_append_64(&packet, GIF_REG_RGBAQ);

	packet_append_64(&packet, GIF_SET_ALPHA(0, 1,0,1,0));
	packet_append_64(&packet, GIF_REG_ALPHA_1);

	/* GIF_SET_PRIM(prim type, Shading, Texture, Fog, Alpha, AA, STQ/UV, context, fragmtnt*/
	packet_append_64(&packet, GIF_SET_PRIM (6, 0, 1, 0, 1, 0, 1, 0, 0));
	packet_append_64(&packet, GIF_REG_PRIM);
}
Exemplo n.º 3
0
/**
 * Alloc a new heap and space for data.
 * @param size - if size <= 0, alloc a default size, else alloc 2^(log2(n)+1)
 * @return 0 on success
 */
int alloc_int_heap(heap_int_t** heap, enum heap_type_t type, int size)
{
	int n;
	heap_int_t* h;

	if (*heap != NULL)
		return ENULL;

	h = (heap_int_t*)malloc(sizeof(heap_int_t));
	if (!h)
		return EALLOC;

	if (size <= 0)
		n = 1 << DEFAULT_LEVELS;
	else
		n = 1 << (mylog2(size) + 1);

	h->data = (typeof(h->data))malloc(n * sizeof(h->data));
	if (!(h->data)) {
		free(h);
		return EALLOC;
	}
	h->size = 0;
	h->nalloc = n;
	h->type = type;
	*heap = h;

	return SUCCESS;
}
Exemplo n.º 4
0
Arquivo: buddy.c Projeto: onkwon/yaos
static void buddy_freelist_init(struct buddy *node, size_t nr_pages,
		struct page *mem_map)
{
	extern unsigned int _ram_start;
	unsigned int order, idx, preserved, nr_free, n;

	/* Preserve the initial kernel stack to be free later, which is located
	 * at the end of memory */
	preserved = nr_pages - PAGE_NR(ALIGN_PAGE(STACK_SIZE));
	order = mylog2(PAGE_NR(ALIGN_PAGE(STACK_SIZE)));
	SET_PAGE_ORDER(&mem_map[preserved], order);

	/* And mark kernel .data and .bss sections as used.
	 * The region of mem_map array as well. */
	idx = PAGE_NR(ALIGN_PAGE(&mem_map[nr_pages]) -
			(unsigned int)&_ram_start);
	nr_free = preserved - idx;
	debug(MSG_DEBUG, "The first free page(idx:%d) - %x",
			idx, &mem_map[nr_pages]);
	debug(MSG_DEBUG, "The number of free pages %d", nr_free);

	struct page *page;

	while (nr_free) {
		order = min(mylog2(idx), BUDDY_MAX_ORDER - 1);
		while ((int)(nr_free - (1U << order)) < 0)
			order--;

		page = &mem_map[idx];
		SET_PAGE_ORDER(page, order);
		SET_PAGE_FLAG(page, PAGE_BUDDY);
		links_add(&page->list, &node->freelist[order].list);

		node->freelist[order].nr_pageblocks++;
		debug(MSG_DEBUG, "%02d %x added to %x", order, &page->list,
				&node->freelist[order].list);

		n = 1U << order;
		debug(MSG_DEBUG, "%04d: idx %d buddy %d head %d",
				n, idx, idx ^ n, idx & ~n);
		idx += n;
		nr_free -= n;
		node->nr_free += n; /* total pages being managed by buddy */
		debug(MSG_DEBUG, "order %d, nr_free %d, next %d\n",
				order, nr_free, idx);
	}
}
Exemplo n.º 5
0
void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd)
{
    uchar *byteptr;
    int temp;

    byteptr = (uchar *) wpmd->temp_data;
    wpmd->data = wpmd->temp_data;
    wpmd->id = ID_ENTROPY_VARS;

    *byteptr++ = temp = mylog2 (wps->w.median [0] [0]);
    *byteptr++ = temp >> 8;
    *byteptr++ = temp = mylog2 (wps->w.median [1] [0]);
    *byteptr++ = temp >> 8;
    *byteptr++ = temp = mylog2 (wps->w.median [2] [0]);
    *byteptr++ = temp >> 8;

    wpmd->byte_length = byteptr - (uchar *) wpmd->data;
    read_entropy_vars (wps, wpmd);
}
Exemplo n.º 6
0
/**
 * Print heap on levels.
 */
void print_tree_int_heap(heap_int_t* heap)
{
	int h, i, j;

	printf("Heap: size=%d, allocated=%d, type=%s\n", heap->size, heap->nalloc, type2name(heap->type));

	i = 0;
	for (h=0; h<=mylog2(heap->size); h++) {
		for (j=0; j<(1<<h) && i<heap->size; j++, i++)
			printf("%d ", heap->data[i]);
		printf("\n");
	}
	printf("Heap end.\n");
}
Exemplo n.º 7
0
void lcaPreprocess()
{
    int treeSize = tree.size();
    
    for(int i=minNode;i<=maxNode;i++)
    {
        if(nodes[i].links.size()>0)
        {
            int parentNode;
            
            if(nodes[i].parent>=0)
            {            
                Edge &e = tree[nodes[i].parent];
                
                if(e.v0 == i) parentNode = e.v1;
                else parentNode = e.v0;    
                
                dp[i][0] = parentNode;
                dpWeight[i][0] = e.weight;
            }
            else
            {
                dp[i][0] = i;
                dpWeight[i][0] = 0;
            }
        }
    }
        
    int logValue = mylog2(treeSize);
        
    for(int j=1;j<=logValue;j++)        
    {
        for(int i=minNode;i<=maxNode;i++)
        {
            if(nodes[i].links.size()>0)
            {
                int weightPrev = dpWeight[i][j-1];
                int weightNext = dpWeight[ dp[i][j - 1] ]   [j - 1];                            
                
                if(weightPrev > weightNext ) dpWeight[i][j] = weightPrev;
                else dpWeight[i][j] = weightNext;
                
                dp[i][j] = dp[ dp[i][j - 1] ]   [j - 1];    
            }
        }
    }
}
Exemplo n.º 8
0
void write_entropy_vars (WavpackStream *wps, WavpackMetadata *wpmd)
{
    uchar *byteptr;
    int temp;

    byteptr = wpmd->data = malloc (12);
    wpmd->id = ID_ENTROPY_VARS;

    *byteptr++ = temp = mylog2 (wps->w.median [0] [0]);
    *byteptr++ = temp >> 8;
    *byteptr++ = temp = mylog2 (wps->w.median [1] [0]);
    *byteptr++ = temp >> 8;
    *byteptr++ = temp = mylog2 (wps->w.median [2] [0]);
    *byteptr++ = temp >> 8;

    if (!(wps->wphdr.flags & MONO_FLAG)) {
	*byteptr++ = temp = mylog2 (wps->w.median [0] [1]);
	*byteptr++ = temp >> 8;
	*byteptr++ = temp = mylog2 (wps->w.median [1] [1]);
	*byteptr++ = temp >> 8;
	*byteptr++ = temp = mylog2 (wps->w.median [2] [1]);
	*byteptr++ = temp >> 8;
    }
Exemplo n.º 9
0
Bool
I810DRIScreenInit(ScreenPtr pScreen)
{
   ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
   I810Ptr pI810 = I810PTR(pScrn);
   DRIInfoPtr pDRIInfo;
   I810DRIPtr pI810DRI;
   unsigned long tom;
   drm_handle_t agpHandle;
   drm_handle_t dcacheHandle;
   int sysmem_size = 0;
   int back_size = 0;
   unsigned int pitch_idx = 0;
   int bufs;
   int width = pScrn->displayWidth * pI810->cpp;
   int i;

   /* Hardware 3D rendering only implemented for 16bpp */
   /* And it only works for 5:6:5 (Mark) */
   if (pScrn->depth != 16)
      return FALSE;

   /* Check that the DRI, and DRM modules have been loaded by testing
    * for known symbols in each module. */
   if (!xf86LoaderCheckSymbol("drmAvailable"))
      return FALSE;
   if (!xf86LoaderCheckSymbol("DRIQueryVersion")) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[dri] I810DRIScreenInit failed (libdri.a too old)\n");
      return FALSE;
   }

   /* adjust width first */
#define Elements(x) sizeof(x)/sizeof(*x)
   for (pitch_idx = 0; pitch_idx < Elements(i810_pitches); pitch_idx++)
      if (width <= i810_pitches[pitch_idx])
	 break;

   if (pitch_idx == Elements(i810_pitches)) {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[dri] Couldn't find depth/back buffer pitch");
      DRICloseScreen(pScreen);
      return FALSE;
   } else {
      /* for tiled memory to work, the buffer needs to have the
       * number of lines as a multiple of 16 (the tile size),
       *  - airlied */
      int lines = (pScrn->virtualY + 15) / 16 * 16;
      back_size = i810_pitches[pitch_idx] * lines;
      back_size = ((back_size + 4096 - 1) / 4096) * 4096;
   }

   pScrn->displayWidth = i810_pitches[pitch_idx] / pI810->cpp;

   /* Check the DRI version */
   {
      int major, minor, patch;

      DRIQueryVersion(&major, &minor, &patch);
      if (major != DRIINFO_MAJOR_VERSION || minor < DRIINFO_MINOR_VERSION) {
	 xf86DrvMsg(pScreen->myNum, X_ERROR,
		    "[dri] I810DRIScreenInit failed because of a version mismatch.\n"
		    "[dri] libdri version is %d.%d.%d bug version %d.%d.x is needed.\n"
		    "[dri] Disabling DRI.\n", major, minor, patch,
                    DRIINFO_MAJOR_VERSION, DRIINFO_MINOR_VERSION);
	 return FALSE;
      }
   }

   pDRIInfo = DRICreateInfoRec();
   if (!pDRIInfo) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[dri] DRICreateInfoRec failed.  Disabling DRI.\n");
      return FALSE;
   }

/*     pDRIInfo->wrap.ValidateTree = 0;    */
/*     pDRIInfo->wrap.PostValidateTree = 0;    */

   pI810->pDRIInfo = pDRIInfo;
   pI810->LockHeld = 0;

   pDRIInfo->drmDriverName = I810KernelDriverName;
   pDRIInfo->clientDriverName = I810ClientDriverName;
   if (xf86LoaderCheckSymbol("DRICreatePCIBusID")) {
      pDRIInfo->busIdString = DRICreatePCIBusID(pI810->PciInfo);
   } else {
      pDRIInfo->busIdString = malloc(64);
      if (pDRIInfo->busIdString)
	 sprintf(pDRIInfo->busIdString, "PCI:%d:%d:%d",
		 ((pI810->PciInfo->domain << 8) | pI810->PciInfo->bus),
		 pI810->PciInfo->dev, pI810->PciInfo->func
		);
   }
   if (!pDRIInfo->busIdString) {
      DRIDestroyInfoRec(pI810->pDRIInfo);
      pI810->pDRIInfo = NULL;
      return FALSE;
   }
   pDRIInfo->ddxDriverMajorVersion = I810_MAJOR_VERSION;
   pDRIInfo->ddxDriverMinorVersion = I810_MINOR_VERSION;
   pDRIInfo->ddxDriverPatchVersion = I810_PATCHLEVEL;
   pDRIInfo->frameBufferPhysicalAddress = (pointer) pI810->LinearAddr;
   pDRIInfo->frameBufferSize = (((pScrn->displayWidth *
				  pScrn->virtualY * pI810->cpp) +
				 4096 - 1) / 4096) * 4096;

   pDRIInfo->frameBufferStride = pScrn->displayWidth * pI810->cpp;
   pDRIInfo->ddxDrawableTableEntry = I810_MAX_DRAWABLES;

   if (SAREA_MAX_DRAWABLES < I810_MAX_DRAWABLES)
      pDRIInfo->maxDrawableTableEntry = SAREA_MAX_DRAWABLES;
   else
      pDRIInfo->maxDrawableTableEntry = I810_MAX_DRAWABLES;

   /* For now the mapping works by using a fixed size defined
    * in the SAREA header
    */
   if (sizeof(XF86DRISAREARec) + sizeof(I810SAREARec) > SAREA_MAX) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[dri] Data does not fit in SAREA\n");
      return FALSE;
   }
   pDRIInfo->SAREASize = SAREA_MAX;

   if (!(pI810DRI = (I810DRIPtr) calloc(sizeof(I810DRIRec), 1))) {
      DRIDestroyInfoRec(pI810->pDRIInfo);
      pI810->pDRIInfo = NULL;
      return FALSE;
   }
   pDRIInfo->devPrivate = pI810DRI;
   pDRIInfo->devPrivateSize = sizeof(I810DRIRec);
   pDRIInfo->contextSize = sizeof(I810DRIContextRec);

   pDRIInfo->CreateContext = I810CreateContext;
   pDRIInfo->DestroyContext = I810DestroyContext;
   pDRIInfo->SwapContext = I810DRISwapContext;
   pDRIInfo->InitBuffers = I810DRIInitBuffers;
   pDRIInfo->MoveBuffers = I810DRIMoveBuffers;
   pDRIInfo->bufferRequests = DRI_ALL_WINDOWS;
   pDRIInfo->TransitionTo2d = I810DRITransitionTo2d;
   pDRIInfo->TransitionTo3d = I810DRITransitionTo3d;
   pDRIInfo->TransitionSingleToMulti3D = I810DRITransitionSingleToMulti3d;
   pDRIInfo->TransitionMultiToSingle3D = I810DRITransitionMultiToSingle3d;

   pDRIInfo->createDummyCtx = TRUE;
   pDRIInfo->createDummyCtxPriv = FALSE;

   /* This adds the framebuffer as a drm map *before* we have asked agp
    * to allocate it.  Scary stuff, hold on...
    */
   if (!DRIScreenInit(pScreen, pDRIInfo, &pI810->drmSubFD)) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[dri] DRIScreenInit failed.  Disabling DRI.\n");
      free(pDRIInfo->devPrivate);
      pDRIInfo->devPrivate = NULL;
      DRIDestroyInfoRec(pI810->pDRIInfo);
      pI810->pDRIInfo = NULL;
      return FALSE;
   }

   /* Check the i810 DRM versioning */
   {
      drmVersionPtr version;

      /* Check the DRM lib version.
       * drmGetLibVersion was not supported in version 1.0, so check for
       * symbol first to avoid possible crash or hang.
       */
      if (xf86LoaderCheckSymbol("drmGetLibVersion")) {
	 version = drmGetLibVersion(pI810->drmSubFD);
      } else
      {
	 /* drmlib version 1.0.0 didn't have the drmGetLibVersion
	  * entry point.  Fake it by allocating a version record
	  * via drmGetVersion and changing it to version 1.0.0
	  */
	 version = drmGetVersion(pI810->drmSubFD);
	 version->version_major = 1;
	 version->version_minor = 0;
	 version->version_patchlevel = 0;
      }

#define REQ_MAJ 1
#define REQ_MIN 1
      if (version) {
	 if (version->version_major != REQ_MAJ ||
	     version->version_minor < REQ_MIN) {
	    /* incompatible drm library version */
	    xf86DrvMsg(pScreen->myNum, X_ERROR,
		       "[dri] I810DRIScreenInit failed because of a version mismatch.\n"
		       "[dri] libdrm.a module version is %d.%d.%d but version %d.%d.x is needed.\n"
		       "[dri] Disabling DRI.\n",
		       version->version_major,
		       version->version_minor, version->version_patchlevel,
		       REQ_MAJ, REQ_MIN);
	    drmFreeVersion(version);
	    I810DRICloseScreen(pScreen);
	    return FALSE;
	 }
	 drmFreeVersion(version);
      }

      /* Check the i810 DRM version */
      version = drmGetVersion(pI810->drmSubFD);
      if (version) {
	i810_drm_version = (version->version_major<<16) |
	                    version->version_minor;
	 if (version->version_major != 1 || version->version_minor < 2) {
	    /* incompatible drm version */
	    xf86DrvMsg(pScreen->myNum, X_ERROR,
		       "[dri] I810DRIScreenInit failed because of a version mismatch.\n"
		       "[dri] i810.o kernel module version is %d.%d.%d but version 1.2.0 or greater is needed.\n"
		       "[dri] Disabling DRI.\n",
		       version->version_major,
		       version->version_minor, version->version_patchlevel);
	    I810DRICloseScreen(pScreen);
	    drmFreeVersion(version);
	    return FALSE;
	 }
         pI810->drmMinor = version->version_minor;
	 drmFreeVersion(version);
      }
   }

   pI810DRI->regsSize = I810_REG_SIZE;
   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->MMIOAddr,
		 pI810DRI->regsSize, DRM_REGISTERS, 0,
		 (drmAddress) &pI810DRI->regs) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR, "[drm] drmAddMap(regs) failed\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }
   xf86DrvMsg(pScreen->myNum, X_INFO, "[drm] Registers = 0x%08x\n",
	      (int)pI810DRI->regs);

   pI810->backHandle = DRM_AGP_NO_HANDLE;
   pI810->zHandle = DRM_AGP_NO_HANDLE;
   pI810->cursorHandle = DRM_AGP_NO_HANDLE;
   pI810->xvmcHandle = DRM_AGP_NO_HANDLE;
   pI810->sysmemHandle = DRM_AGP_NO_HANDLE;
   pI810->agpAcquired = FALSE;
   pI810->dcacheHandle = DRM_AGP_NO_HANDLE;

   /* Agp Support - Need this just to get the framebuffer.
    */
   if (drmAgpAcquire(pI810->drmSubFD) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR, "[agp] drmAgpAquire failed\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }
   pI810->agpAcquired = TRUE;

   if (drmAgpEnable(pI810->drmSubFD, 0) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR, "[agp] drmAgpEnable failed\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   memset(&pI810->DcacheMem, 0, sizeof(I810MemRange));
   memset(&pI810->BackBuffer, 0, sizeof(I810MemRange));
   memset(&pI810->DepthBuffer, 0, sizeof(I810MemRange));
   pI810->CursorPhysical = 0;
   pI810->CursorARGBPhysical = 0;

   /* Dcache - half the speed of normal ram, but has use as a Z buffer
    * under the DRI.
    */

   drmAgpAlloc(pI810->drmSubFD, 4096 * 1024, 1, NULL,
	       (drmAddress) &dcacheHandle);
   pI810->dcacheHandle = dcacheHandle;

   xf86DrvMsg(pScreen->myNum, X_INFO, "[agp] dcacheHandle : 0x%x\n",
	      (int)dcacheHandle);

   sysmem_size = pScrn->videoRam * 1024;
   if (dcacheHandle != DRM_AGP_NO_HANDLE) {
      if (back_size > 4 * 1024 * 1024) {
	 xf86DrvMsg(pScreen->myNum, X_INFO,
		    "[dri] Backsize is larger then 4 meg\n");
	 sysmem_size = sysmem_size - 2 * back_size;
	 drmAgpFree(pI810->drmSubFD, dcacheHandle);
	 pI810->dcacheHandle = dcacheHandle = DRM_AGP_NO_HANDLE;
      } else {
	 sysmem_size = sysmem_size - back_size;
      }
   } else {
      sysmem_size = sysmem_size - 2 * back_size;
   }

   /* Max size is 48 without XvMC, 41 with 6 surfaces, 40 with 7 surfaces */
   if (pI810->numSurfaces && (pI810->numSurfaces == 6)) {
      if (sysmem_size > (pI810->FbMapSize - 7 * 1024 * 1024)) {
	 sysmem_size = (pI810->FbMapSize - 7 * 1024 * 1024);
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "User requested more memory then fits in the agp aperture\n"
		    "Truncating to %d bytes of memory\n", sysmem_size);
      }
   }
   if (pI810->numSurfaces && (pI810->numSurfaces == 7)) {
      if (sysmem_size > (pI810->FbMapSize - 8 * 1024 * 1024)) {
	 sysmem_size = (pI810->FbMapSize - 8 * 1024 * 1024);
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "User requested more memory then fits in the agp aperture\n"
		    "Truncating to %d bytes of memory\n", sysmem_size);
      }
   }

   if (sysmem_size > pI810->FbMapSize) {
      sysmem_size = pI810->FbMapSize;

      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[dri] User requested more memory then fits in the agp"
		 " aperture\n\tTruncating to %d bytes of memory\n",
		 sysmem_size);
   }

   sysmem_size -= 4096;			/* remove 4k for the hw cursor */
   sysmem_size -= 16384;		/* remove 16k for the ARGB hw cursor */

   pI810->SysMem.Start = 0;
   pI810->SysMem.Size = sysmem_size;
   pI810->SysMem.End = sysmem_size;
   tom = sysmem_size;

   pI810->SavedSysMem = pI810->SysMem;

   if (dcacheHandle != DRM_AGP_NO_HANDLE) {
      if (drmAgpBind(pI810->drmSubFD, dcacheHandle, pI810->DepthOffset) == 0) {
	 memset(&pI810->DcacheMem, 0, sizeof(I810MemRange));
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: Found 4096K Z buffer memory\n");
	 pI810->DcacheMem.Start = pI810->DepthOffset;
	 pI810->DcacheMem.Size = 1024 * 4096;
	 pI810->DcacheMem.End =
	       pI810->DcacheMem.Start + pI810->DcacheMem.Size;
	 if (!I810AllocLow
	     (&(pI810->DepthBuffer), &(pI810->DcacheMem), back_size)) {
	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		       "[agp] Depth buffer allocation failed\n");
	    DRICloseScreen(pScreen);
	    return FALSE;
	 }
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: dcache bind failed\n");
	 drmAgpFree(pI810->drmSubFD, dcacheHandle);
	 pI810->dcacheHandle = dcacheHandle = DRM_AGP_NO_HANDLE;
      }
   } else {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[agp] GART: no dcache memory found\n");
   }

   drmAgpAlloc(pI810->drmSubFD, back_size, 0, NULL,
	       (drmAddress) &agpHandle);
   pI810->backHandle = agpHandle;

   if (agpHandle != DRM_AGP_NO_HANDLE) {
      if (drmAgpBind(pI810->drmSubFD, agpHandle, pI810->BackOffset) == 0) {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] Bound backbuffer memory\n");

	 pI810->BackBuffer.Start = pI810->BackOffset;
	 pI810->BackBuffer.Size = back_size;
	 pI810->BackBuffer.End = (pI810->BackBuffer.Start +
				  pI810->BackBuffer.Size);
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] Unable to bind backbuffer.  Disabling DRI.\n");
	 DRICloseScreen(pScreen);
	 return FALSE;
      }
   } else {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[dri] Unable to allocate backbuffer memory.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   if (dcacheHandle == DRM_AGP_NO_HANDLE) {
     drmAgpAlloc(pI810->drmSubFD, back_size, 0, NULL,
		 (drmAddress) &agpHandle);

      pI810->zHandle = agpHandle;

      if (agpHandle != DRM_AGP_NO_HANDLE) {
	 if (drmAgpBind(pI810->drmSubFD, agpHandle, pI810->DepthOffset) == 0) {
	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		       "[agp] Bound depthbuffer memory\n");
	    pI810->DepthBuffer.Start = pI810->DepthOffset;
	    pI810->DepthBuffer.Size = back_size;
	    pI810->DepthBuffer.End = (pI810->DepthBuffer.Start +
				      pI810->DepthBuffer.Size);
	 } else {
	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		       "[agp] Unable to bind depthbuffer.  Disabling DRI.\n");
	    DRICloseScreen(pScreen);
	    return FALSE;
	 }
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] Unable to allocate depthbuffer memory.  Disabling DRI.\n");
	 DRICloseScreen(pScreen);
	 return FALSE;
      }
   }

   /* Now allocate and bind the agp space.  This memory will include the
    * regular framebuffer as well as texture memory.
    */
   drmAgpAlloc(pI810->drmSubFD, sysmem_size, 0, NULL,
	       (drmAddress)&agpHandle);
   pI810->sysmemHandle = agpHandle;

   if (agpHandle != DRM_AGP_NO_HANDLE) {
      if (drmAgpBind(pI810->drmSubFD, agpHandle, 0) == 0) {
	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		   "[agp] Bound System Texture Memory\n");
      } else {
          xf86DrvMsg(pScreen->myNum, X_ERROR, "[agp] Unable to bind system texture memory. Disabling DRI.\n");
	  DRICloseScreen(pScreen);
	  return FALSE;
      }
   } else {
      xf86DrvMsg(pScreen->myNum, X_ERROR, "[agp] Unable to allocate system texture memory. Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

/* Allocate 7 or 8MB for XvMC this is setup as follows to best use tiled
   regions and required surface pitches. (Numbers are adjusted if the
   AGP region is only 32MB
   For numSurfaces == 6
   44 - 48MB = 4MB Fence, 8 Tiles wide
   43 - 44MB = 1MB Fence, 8 Tiles wide
   42 - 43MB = 1MB Fence, 4 Tiles wide
   41 - 42MB = 1MB Fence, 4 Tiles wide
   For numSurfaces == 7
   44 - 48MB   = 4MB Fence, 8 Tiles wide
   43 - 44MB   = 1MB Fence, 8 Tiles wide
   42.5 - 43MB = 0.5MB Fence, 8 Tiles wide
   42 - 42.5MB = 0.5MB Fence, 4 Tiles wide
   40 - 42MB   = 2MB Fence, 4 Tiles wide
 */
   if (pI810->numSurfaces) {
      if (pI810->numSurfaces == 6) {
	 pI810->MC.Size = 7 * 1024 * 1024;
	 pI810->MC.Start = pI810->FbMapSize - 7 * 1024 * 1024;

      }
      if (pI810->numSurfaces == 7) {
	 pI810->MC.Size = 8 * 1024 * 1024;
	 pI810->MC.Start = pI810->FbMapSize - 8 * 1024 * 1024;
      }
      drmAgpAlloc(pI810->drmSubFD, pI810->MC.Size, 0, NULL,
		  (drmAddress) &agpHandle);

      pI810->xvmcHandle = agpHandle;

      if (agpHandle != DRM_AGP_NO_HANDLE) {
	 if (drmAgpBind(pI810->drmSubFD, agpHandle, pI810->MC.Start) == 0) {
	    xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		       "GART: Allocated 7MB for HWMC\n");
	    pI810->MC.End = pI810->MC.Start + pI810->MC.Size;
	 } else {
	    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "GART: HWMC bind failed\n");
	    pI810->MC.Start = 0;
	    pI810->MC.Size = 0;
	    pI810->MC.End = 0;
	 }
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO, "GART: HWMC alloc failed\n");
	 pI810->MC.Start = 0;
	 pI810->MC.Size = 0;
	 pI810->MC.End = 0;
      }
      pI810->xvmcContext = 0;
   }

   drmAgpAlloc(pI810->drmSubFD, 4096, 2,
	       (unsigned long *)&pI810->CursorPhysical,
	       (drmAddress) &agpHandle);

   pI810->cursorHandle = agpHandle;

   if (agpHandle != DRM_AGP_NO_HANDLE) {
      tom = sysmem_size;

      if (drmAgpBind(pI810->drmSubFD, agpHandle, tom) == 0) {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: Allocated 4K for mouse cursor image\n");
	 pI810->CursorStart = tom;
	 tom += 4096;
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: cursor bind failed\n");
	 pI810->CursorPhysical = 0;
      }
   } else {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[agp] GART: cursor alloc failed\n");
      pI810->CursorPhysical = 0;
   }

   drmAgpAlloc(pI810->drmSubFD, 16384, 2,
	       (unsigned long *)&pI810->CursorARGBPhysical,
	       (drmAddress) &agpHandle);

   pI810->cursorARGBHandle = agpHandle;

   if (agpHandle != DRM_AGP_NO_HANDLE) {
      if (drmAgpBind(pI810->drmSubFD, agpHandle, tom) == 0) {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: Allocated 16K for ARGB mouse cursor image\n");
	 pI810->CursorARGBStart = tom;
	 tom += 16384;
      } else {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[agp] GART: ARGB cursor bind failed\n");
	 pI810->CursorARGBPhysical = 0;
      }
   } else {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[agp] GART: ARGB cursor alloc failed\n");
      pI810->CursorARGBPhysical = 0;
   }

   /* Steal some of the excess cursor space for the overlay regs.
    */
   pI810->OverlayPhysical = pI810->CursorPhysical + 1024;
   pI810->OverlayStart = pI810->CursorStart + 1024;

   I810SetTiledMemory(pScrn, 1,
		      pI810->DepthBuffer.Start,
		      i810_pitches[pitch_idx], 8 * 1024 * 1024);

   I810SetTiledMemory(pScrn, 2,
		      pI810->BackBuffer.Start,
		      i810_pitches[pitch_idx], 8 * 1024 * 1024);

   /* These are for HWMC surfaces */
   if (pI810->numSurfaces == 6) {
      I810SetTiledMemory(pScrn, 3, pI810->MC.Start, 512, 1024 * 1024);

      I810SetTiledMemory(pScrn, 4,
			 pI810->MC.Start + 1024 * 1024, 512, 1024 * 1024);

      I810SetTiledMemory(pScrn, 5,
			 pI810->MC.Start + 1024 * 1024 * 2,
			 1024, 1024 * 1024);

      I810SetTiledMemory(pScrn, 6,
			 pI810->MC.Start + 1024 * 1024 * 3,
			 1024, 4 * 1024 * 1024);
   }
   if (pI810->numSurfaces == 7) {
      I810SetTiledMemory(pScrn, 3, pI810->MC.Start, 512, 2 * 1024 * 1024);

      I810SetTiledMemory(pScrn, 4,
			 pI810->MC.Start + 2 * 1024 * 1024, 512, 512 * 1024);

      I810SetTiledMemory(pScrn, 5,
			 pI810->MC.Start + 2 * 1024 * 1024 + 512 * 1024,
			 1024, 512 * 1024);

      I810SetTiledMemory(pScrn, 6,
			 pI810->MC.Start + 3 * 1024 * 1024,
			 1024, 1 * 1024 * 1024);

      I810SetTiledMemory(pScrn, 7,
			 pI810->MC.Start + 4 * 1024 * 1024,
			 1024, 4 * 1024 * 1024);

   }

   pI810->auxPitch = i810_pitches[pitch_idx];
   pI810->auxPitchBits = i810_pitch_flags[pitch_idx];
   pI810->SavedDcacheMem = pI810->DcacheMem;
   pI810DRI->backbufferSize = pI810->BackBuffer.Size;

   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->BackBuffer.Start,
		 pI810->BackBuffer.Size, DRM_AGP, 0,
		 (drmAddress) &pI810DRI->backbuffer) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] drmAddMap(backbuffer) failed.  Disabling DRI\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   pI810DRI->depthbufferSize = pI810->DepthBuffer.Size;
   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->DepthBuffer.Start,
		 pI810->DepthBuffer.Size, DRM_AGP, 0,
		 (drmAddress) &pI810DRI->depthbuffer) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] drmAddMap(depthbuffer) failed.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   /* Allocate FrontBuffer etc. */
   if (!I810AllocateFront(pScrn)) {
      DRICloseScreen(pScreen);
      return FALSE;
   }

   /* Allocate buffer memory */
   I810AllocHigh(&(pI810->BufferMem), &(pI810->SysMem),
		 I810_DMA_BUF_NR * I810_DMA_BUF_SZ);

   xf86DrvMsg(pScreen->myNum, X_INFO, "[dri] Buffer map : %lx\n",
	      pI810->BufferMem.Start);

   if (pI810->BufferMem.Start == 0 ||
       pI810->BufferMem.End - pI810->BufferMem.Start >
       I810_DMA_BUF_NR * I810_DMA_BUF_SZ) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[dri] Not enough memory for dma buffers.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }
   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->BufferMem.Start,
		 pI810->BufferMem.Size, DRM_AGP, 0,
		 (drmAddress) &pI810->buffer_map) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] drmAddMap(buffer_map) failed.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   pI810DRI->agp_buffers = pI810->buffer_map;
   pI810DRI->agp_buf_size = pI810->BufferMem.Size;

   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->LpRing->mem.Start,
		 pI810->LpRing->mem.Size, DRM_AGP, 0,
		 (drmAddress) &pI810->ring_map) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] drmAddMap(ring_map) failed.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   /* Use the rest of memory for textures. */
   pI810DRI->textureSize = pI810->SysMem.Size;

   i = mylog2(pI810DRI->textureSize / I810_NR_TEX_REGIONS);

   if (i < I810_LOG_MIN_TEX_REGION_SIZE)
      i = I810_LOG_MIN_TEX_REGION_SIZE;

   pI810DRI->logTextureGranularity = i;
   pI810DRI->textureSize = (pI810DRI->textureSize >> i) << i;	/* truncate */

   if (pI810DRI->textureSize < 512 * 1024) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] Less then 512k memory left for textures.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   if (!I810AllocLow(&(pI810->TexMem), &(pI810->SysMem), pI810DRI->textureSize)) {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[agp] Texure memory allocation failed\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   if (drmAddMap(pI810->drmSubFD, (drm_handle_t) pI810->TexMem.Start,
		 pI810->TexMem.Size, DRM_AGP, 0,
		 (drmAddress) &pI810DRI->textures) < 0) {
      xf86DrvMsg(pScreen->myNum, X_ERROR,
		 "[drm] drmAddMap(textures) failed.  Disabling DRI.\n");
      DRICloseScreen(pScreen);
      return FALSE;
   }

   if ((bufs = drmAddBufs(pI810->drmSubFD,
			  I810_DMA_BUF_NR,
			  I810_DMA_BUF_SZ,
			  DRM_AGP_BUFFER, pI810->BufferMem.Start)) <= 0) {
      xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		 "[drm] failure adding %d %d byte DMA buffers.  Disabling DRI.\n",
		 I810_DMA_BUF_NR, I810_DMA_BUF_SZ);
      DRICloseScreen(pScreen);
      return FALSE;
   }

   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
	      "[drm] added %d %d byte DMA buffers\n", bufs, I810_DMA_BUF_SZ);

   I810InitDma(pScrn);

   /* Okay now initialize the dma engine */

   if (!pI810DRI->irq) {
      pI810DRI->irq = drmGetInterruptFromBusID(pI810->drmSubFD,
					       ((pI810->PciInfo->domain << 8) |
						pI810->PciInfo->bus),
					       pI810->PciInfo->dev,
					       pI810->PciInfo->func
					       );
      if ((drmCtlInstHandler(pI810->drmSubFD, pI810DRI->irq)) != 0) {
	 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
		    "[drm] failure adding irq handler, there is a device "
		    "already using that irq\n Consider rearranging your "
		    "PCI cards.  Disabling DRI.\n");
	 DRICloseScreen(pScreen);
	 return FALSE;
      }
   }

   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
	      "[drm] dma control initialized, using IRQ %d\n", pI810DRI->irq);

   pI810DRI->deviceID = pI810->PciInfo->device_id;
   pI810DRI->width = pScrn->virtualX;
   pI810DRI->height = pScrn->virtualY;
   pI810DRI->mem = pScrn->videoRam * 1024;
   pI810DRI->cpp = pI810->cpp;

   pI810DRI->fbOffset = pI810->FrontBuffer.Start;
   pI810DRI->fbStride = pI810->auxPitch;

   pI810DRI->bitsPerPixel = pScrn->bitsPerPixel;

   pI810DRI->textureOffset = pI810->TexMem.Start;

   pI810DRI->backOffset = pI810->BackBuffer.Start;
   pI810DRI->depthOffset = pI810->DepthBuffer.Start;

   pI810DRI->ringOffset = pI810->LpRing->mem.Start;
   pI810DRI->ringSize = pI810->LpRing->mem.Size;

   pI810DRI->auxPitch = pI810->auxPitch;
   pI810DRI->auxPitchBits = pI810->auxPitchBits;
   pI810DRI->sarea_priv_offset = sizeof(XF86DRISAREARec);

   xf86DrvMsg(pScrn->scrnIndex, X_INFO,
	      "[dri] visual configs initialized.\n");
   pI810->pDRIInfo->driverSwapMethod = DRI_HIDE_X_CONTEXT;

   return TRUE;
}
Exemplo n.º 10
0
void mergesort(int *array, int n)
{
	int 
		core_n = omp_get_num_procs(),
		i,
		j,
		block_size = 1,
		depth = mylog2(n),
		id,
		number_of_blocks,
		number_of_block_pairs,
		number_of_required_cores,
		number_of_block_pairs_per_thread,
		block_start1,
		block_end1,
		block_start2,
		block_end2,
		temp,
		a,
		b,
		c,
		*src = array,
		*dst,
		*ptemp,
		k;
	;

	dst = (int *)malloc(sizeof(int) * n);

	omp_set_num_threads(core_n);

	for(i = 0 ; i < depth ; ++i) 
	{
		//block_size 짜리 두개를 merge하자
		number_of_blocks = n / block_size;
		number_of_block_pairs = number_of_blocks / 2;
		number_of_required_cores = core_n;

		if(number_of_block_pairs < core_n){ //코어 숫자보다 블록 페어 수가 적으면 코어를 다 쓸필요가 없음 
			omp_set_num_threads(number_of_block_pairs);
			number_of_required_cores = number_of_block_pairs;
		}
		number_of_block_pairs_per_thread = number_of_block_pairs / number_of_required_cores;
		if(number_of_block_pairs % number_of_required_cores > 0)
			number_of_block_pairs_per_thread ++;
	
		#pragma omp parallel private(id, block_start1, block_start2, block_end1, block_end2, a, b, c, j)
		{
			id = omp_get_thread_num();
			for(j=0;j<number_of_block_pairs_per_thread;++j){
				block_start1 = id * number_of_block_pairs_per_thread * block_size * 2 + (j * 2 + 0) * block_size;
				block_end1 = block_start1 + block_size;
				block_start2 = id * number_of_block_pairs_per_thread * block_size * 2 + (j * 2 + 1) * block_size;
				block_end2 = block_start2 + block_size;

				if(block_start1 >= n)break;
				if(block_end2 >= n)block_end2 = n;

				c = block_start1;

				while(block_start1 < block_end1 && block_start2 < block_end2){
					a = src[block_start1];
					b = src[block_start2];
					
					if(a<b){ //앞에 있는것이 작으면 이걸 넣자 
						dst/*[id]*/[c++] = a;
						block_start1++;
					}
					else{ //뒤에 있는것이 작으면 이걸 넣자
						dst/*[id]*/[c++] = b;
						block_start2++;
					}
				}
				while(block_start1 < block_end1)dst/*[id]*/[c++] = src[block_start1++];
				while(block_start2 < block_end2)dst/*[id]*/[c++] = src[block_start2++];
			}
		}
		
		ptemp = src;
		src = dst;
		dst = ptemp;

		block_size <<= 1;
	}

	if(i % 2){
		//결과가 src 
		for(i=0;i<n;++i)array[i] = src[i];
		free(src);
	}else{
		free(dst);
	}
}
Exemplo n.º 11
0
int Zoltan_ParMetis_Order(
  ZZ *zz,               /* Zoltan structure */
  int num_obj,          /* Number of (local) objects to order. */
  ZOLTAN_ID_PTR gids,   /* List of global ids (local to this proc) */
                        /* The application must allocate enough space */
  ZOLTAN_ID_PTR lids,   /* List of local ids (local to this proc) */
                        /* The application must allocate enough space */
  ZOLTAN_ID_PTR rank,   /* rank[i] is the rank of gids[i] */
  int *iperm,
  ZOOS *order_opt       /* Ordering options, parsed by Zoltan_Order */
)
{
  static char *yo = "Zoltan_ParMetis_Order";
  int i, n, ierr;
  ZOLTAN_Output_Order ord;
  ZOLTAN_Third_Graph gr;

#ifdef ZOLTAN_PARMETIS
  MPI_Comm comm = zz->Communicator;/* don't want to risk letting external 
                                      packages changing our communicator */
#endif
  indextype numflag = 0;

  int timer_p = 0;
  int get_times = 0;
  int use_timers = 0;
  double times[5];

  ZOLTAN_ID_PTR       l_gids = NULL;
  ZOLTAN_ID_PTR       l_lids = NULL;

  indextype options[MAX_PARMETIS_OPTIONS];
  char alg[MAX_PARAM_STRING_LEN];

  ZOLTAN_TRACE_ENTER(zz, yo);

#ifdef ZOLTAN_PARMETIS
#if TPL_USE_DATATYPE != TPL_METIS_DATATYPES

#ifdef TPL_FLOAT_WEIGHT
  i = 1;
#else
  i = 0;
#endif

  if ((sizeof(indextype) != sizeof(idxtype)) ||
      (sizeof(weighttype) != sizeof(idxtype)) || i){

    ZOLTAN_THIRD_ERROR(ZOLTAN_FATAL,
          "Not supported: Multiple 3rd party libraries with incompatible "
          "data types.");
    return ZOLTAN_FATAL;
  }
#endif
#endif

  memset(&gr, 0, sizeof(ZOLTAN_Third_Graph));
  memset(&ord, 0, sizeof(ZOLTAN_Output_Order));
  memset(times, 0, sizeof(times));

  ord.order_opt = order_opt;

  if (!order_opt){
    /* If for some reason order_opt is NULL, allocate a new ZOOS here. */
    /* This should really never happen. */
    order_opt = (ZOOS *) ZOLTAN_MALLOC(sizeof(ZOOS));
    strcpy(order_opt->method,"PARMETIS");
  }

  ierr = Zoltan_Parmetis_Parse(zz, options, alg, NULL, NULL, &ord);
  /* ParMetis only computes the rank vector */
  order_opt->return_args = RETURN_RANK;

  /* Check that num_obj equals the number of objects on this proc. */
  /* This constraint may be removed in the future. */
  n = zz->Get_Num_Obj(zz->Get_Num_Obj_Data, &ierr);
  if ((ierr!= ZOLTAN_OK) && (ierr!= ZOLTAN_WARN)){
    /* Return error code */
    ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Get_Num_Obj returned error.");
    return(ZOLTAN_FATAL);
  }
  if (n != num_obj){
    /* Currently this is a fatal error. */
    ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Input num_obj does not equal the "
                                     "number of objects.");
    return(ZOLTAN_FATAL);
  }

  /* Do not use weights for ordering */
  gr.obj_wgt_dim = -1;
  gr.edge_wgt_dim = -1;
  gr.num_obj = num_obj;

  /* Check what ordering type is requested */
  if (order_opt){
      SET_GLOBAL_GRAPH(&gr.graph_type); /* GLOBAL by default */

#ifdef ZOLTAN_PARMETIS
      if ((strcmp(order_opt->method, "METIS") == 0))
#endif /* ZOLTAN_PARMETIS */
      SET_LOCAL_GRAPH(&gr.graph_type);
  }
  gr.get_data = 1;

  if (IS_LOCAL_GRAPH(gr.graph_type) && zz->Num_Proc > 1) {
    ZOLTAN_PRINT_ERROR(zz->Proc, yo, "Serial ordering on more than 1 process: "
                                     "set ParMetis instead.");
    return(ZOLTAN_FATAL);
  }

  timer_p = Zoltan_Preprocess_Timer(zz, &use_timers);

    /* Start timer */
  get_times = (zz->Debug_Level >= ZOLTAN_DEBUG_ATIME);
  if (get_times){
    MPI_Barrier(zz->Communicator);
    times[0] = Zoltan_Time(zz->Timer);
  }

  ierr = Zoltan_Preprocess_Graph(zz, &l_gids, &l_lids,  &gr, NULL, NULL, NULL);
  if ((ierr != ZOLTAN_OK) && (ierr != ZOLTAN_WARN)) {
    Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, NULL);
    return (ierr);
  }

  /* Allocate space for separator sizes */

  if (IS_GLOBAL_GRAPH(gr.graph_type)) {
    if (Zoltan_TPL_Order_Init_Tree(&zz->TPL_Order, 2*zz->Num_Proc, zz->Num_Proc) != ZOLTAN_OK) {
      /* Not enough memory */
      Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, &ord);
      ZOLTAN_THIRD_ERROR(ZOLTAN_MEMERR, "Out of memory.");
    }
    ord.sep_sizes = (indextype*)ZOLTAN_MALLOC((2*zz->Num_Proc+1)*sizeof(indextype));
    if (ord.sep_sizes == NULL) {
      Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, &ord);
      ZOLTAN_THIRD_ERROR(ZOLTAN_MEMERR, "Out of memory.");
    }
    memset(ord.sep_sizes, 0, (2*zz->Num_Proc+1)*sizeof(int)); /* It seems parmetis don't initialize correctly */
  }

  /* Allocate space for direct perm */
  ord.rank = (indextype *) ZOLTAN_MALLOC(gr.num_obj*sizeof(indextype));
  if (!ord.rank){
    /* Not enough memory */
    Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, &ord);
    ZOLTAN_THIRD_ERROR(ZOLTAN_MEMERR, "Out of memory.");
  }
  if (IS_LOCAL_GRAPH(gr.graph_type)){
  /* Allocate space for inverse perm */
    ord.iperm = (indextype *) ZOLTAN_MALLOC(gr.num_obj*sizeof(indextype));
    if (!ord.iperm){
      /* Not enough memory */
      Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, &ord);
      ZOLTAN_THIRD_ERROR(ZOLTAN_MEMERR, "Out of memory.");
    }
  }
  else
    ord.iperm = NULL;

  /* Get a time here */
  if (get_times) times[1] = Zoltan_Time(zz->Timer);

#ifdef ZOLTAN_PARMETIS
  if (IS_GLOBAL_GRAPH(gr.graph_type)){
    ZOLTAN_TRACE_DETAIL(zz, yo, "Calling the ParMETIS library");

    ParMETIS_V3_NodeND (gr.vtxdist, gr.xadj, gr.adjncy, 
                        &numflag, options, ord.rank, ord.sep_sizes, &comm);
    ZOLTAN_TRACE_DETAIL(zz, yo, "Returned from the ParMETIS library");

  }
  else
#endif /* ZOLTAN_PARMETIS */
#if defined(ZOLTAN_METIS) || defined(ZOLTAN_PARMETIS)
 if (IS_LOCAL_GRAPH(gr.graph_type)) { /* Be careful : permutation parameters are in the opposite order */
    indextype numobj = gr.num_obj;
    ZOLTAN_TRACE_DETAIL(zz, yo, "Calling the METIS library");
    order_opt->return_args = RETURN_RANK|RETURN_IPERM; /* We provide directly all the permutations */
#if !defined(METIS_VER_MAJOR) || METIS_VER_MAJOR < 5
    options[0] = 0;  /* Use default options for METIS. */
    METIS_NodeND(&numobj, gr.xadj, gr.adjncy, &numflag, options, 
                 ord.iperm, ord.rank);
#else
    METIS_SetDefaultOptions(options);
    METIS_NodeND(&numobj, gr.xadj, gr.adjncy, NULL, options, 
                 ord.iperm, ord.rank); /* NULL is vwgt -- new interface in v4 */
#endif


    ZOLTAN_TRACE_DETAIL(zz, yo, "Returned from the METIS library");
  }
#endif /* ZOLTAN_METIS */

  /* Get a time here */
  if (get_times) times[2] = Zoltan_Time(zz->Timer);

  if (IS_GLOBAL_GRAPH(gr.graph_type)){ /* Update Elimination tree */
    int numbloc;
    int start;
    int leaf;
    int *converttab;
    int levelmax;

    levelmax = mylog2(zz->Num_Proc) + 1;
    converttab = (int*)ZOLTAN_MALLOC(zz->Num_Proc*2*sizeof(int));

    memset(converttab, 0, zz->Num_Proc*2*sizeof(int));
     /* Determine the first node in each separator, store it in zz->TPL_Order.start */
    for (numbloc = 0, start=0, leaf=0; numbloc < zz->Num_Proc /2; numbloc++) {
      int father;

      father = zz->Num_Proc + numbloc;
      converttab[start] = 2*numbloc;
      zz->TPL_Order.leaves[leaf++]=start;
      zz->TPL_Order.ancestor[start] = start + 2;
      converttab[start+1] = 2*numbloc+1;
      zz->TPL_Order.leaves[leaf++]=start+1;
      zz->TPL_Order.ancestor[start+1] = start + 2;
      start+=2;
      do {
        converttab[start] = father;
        if (father %2 == 0) {
          int nextoffset;
          int level;

          level = mylog2(2*zz->Num_Proc - 1 - father);
          nextoffset = (1<<(levelmax-level));
          zz->TPL_Order.ancestor[start] = start+nextoffset;
          start++;
          break;
        }
        else {
          zz->TPL_Order.ancestor[start] = start+1;
          start++;
          father = zz->Num_Proc + father/2;
        }
      } while (father < 2*zz->Num_Proc - 1);
    }

    zz->TPL_Order.start[0] = 0;
    zz->TPL_Order.ancestor [2*zz->Num_Proc - 2] = -1;
    for (numbloc = 1 ; numbloc < 2*zz->Num_Proc ; numbloc++) {
      int oldblock=converttab[numbloc-1];
      zz->TPL_Order.start[numbloc] = zz->TPL_Order.start[numbloc-1] + ord.sep_sizes[oldblock];
    }

    ZOLTAN_FREE(&converttab);
    ZOLTAN_FREE(&ord.sep_sizes);

    zz->TPL_Order.leaves[zz->Num_Proc] = -1;
    zz->TPL_Order.nbr_leaves = zz->Num_Proc;
    zz->TPL_Order.nbr_blocks = 2*zz->Num_Proc-1;
  }
  else { /* No tree */
    zz->TPL_Order.nbr_blocks = 0;
    zz->TPL_Order.start = NULL;
    zz->TPL_Order.ancestor = NULL;
    zz->TPL_Order.leaves = NULL;
  }

  /* Correct because no redistribution */
  memcpy(gids, l_gids, n*zz->Num_GID*sizeof(ZOLTAN_ID_TYPE));
  memcpy(lids, l_lids, n*zz->Num_LID*sizeof(ZOLTAN_ID_TYPE));

  ierr = Zoltan_Postprocess_Graph (zz, l_gids, l_lids, &gr, NULL, NULL, NULL, &ord, NULL);

  ZOLTAN_FREE(&l_gids); 
  ZOLTAN_FREE(&l_lids);

  /* Get a time here */
  if (get_times) times[3] = Zoltan_Time(zz->Timer);

  if (get_times) Zoltan_Third_DisplayTime(zz, times);

  if (use_timers)
    ZOLTAN_TIMER_STOP(zz->ZTime, timer_p, zz->Communicator);

  if (sizeof(indextype) == sizeof(ZOLTAN_ID_TYPE)){
    memcpy(rank, ord.rank, gr.num_obj*sizeof(indextype));
  }
  else{
    for (i=0; i < gr.num_obj; i++){
      rank[i] = (ZOLTAN_ID_TYPE)ord.rank[i];
    }
  }

  if ((ord.iperm != NULL) && (iperm != NULL)){
    if (sizeof(indextype) == sizeof(int)){
      memcpy(iperm, ord.iperm, gr.num_obj*sizeof(indextype));
    }
    else{
      for (i=0; i < gr.num_obj; i++){
        iperm[i] = (int)ord.iperm[i];
      }
    }
  }

  if (ord.iperm != NULL)  ZOLTAN_FREE(&ord.iperm);
  ZOLTAN_FREE(&ord.rank);

  /* Free all other "graph" stuff */
  Zoltan_Third_Exit(&gr, NULL, NULL, NULL, NULL, NULL);

  ZOLTAN_TRACE_EXIT(zz, yo);

  return (ZOLTAN_OK);
}
Exemplo n.º 12
0
static void LoadTexture(ModeInfo * mi, char **fn, const char *filename, GLuint texbind, int blur, float bw_color, Bool anegative, Bool onealpha)
{
	/* looping and temporary array index variables */
	int ix, iy, bx, by, indx, indy, boxsize, cchan, tmpidx, dtaidx;

	float boxdiv, tmpfa, blursum ;
	unsigned char *tmpbuf, tmpa;
	Bool rescale;


        XImage *teximage;    /* Texture data */

	rescale = False;

	boxsize = 2;
	boxdiv = 1.0 / ( boxsize * 2.0 + 1.0) / ( boxsize * 2.0 + 1.0);


	if (filename) 
        	teximage = xpm_file_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi),
                         MI_COLORMAP(mi), filename);
        else 
		teximage = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi),
                         MI_COLORMAP(mi), fn);
	if (teximage == NULL) {
            fprintf(stderr, "%s: error reading the texture.\n", progname);
            glDeleteTextures(1, &texbind);
            do_texture = False;
            exit(0);
        }

	/* check if image is 2^kumquat, where kumquat is an integer between 1 and 10. Recale to
	   nearest power of 2. */
	tmpfa = mylog2((float) teximage->width);
	bx = 2 << (int) (tmpfa -1);
	if (bx != teximage->width) {
		rescale = True;
		if ((tmpfa - (int) tmpfa) >  0.5849)
			bx = bx * 2;
	}
	tmpfa = mylog2((float) teximage->height);
	by = 2 << (int) (tmpfa - 1);
	if (by != teximage->height) {
		rescale = True;
		if ((tmpfa - (int) tmpfa) >  0.5849)
			by = by * 2;
	}

#ifndef HAVE_JWZGLES
	if (rescale) {
		tmpbuf = calloc(bx * by * 4, sizeof(unsigned char));
		if (gluScaleImage(GL_RGBA, teximage->width, teximage->height, GL_UNSIGNED_BYTE, teximage->data,
				bx, by, GL_UNSIGNED_BYTE, tmpbuf))
        		check_gl_error("scale image");
		
		free(teximage->data);
		teximage->data = (char *) tmpbuf;
		teximage->width = bx;
		teximage->height= by;
	}
	/* end rescale code */
#endif /* !HAVE_JWZGLES */
		
	if (anegative ) {
		for (ix = 0 ; ix < teximage->height * teximage->width; ix++)
			{
				if (!teximage->data[ ix * 4 + 3]) {
					teximage->data[ ix * 4 + 3]  = (unsigned char) 0xff;
					tmpa = (unsigned char) (bw_color * 0xff);
			 	} else  {
					if (onealpha)
						teximage->data[ ix * 4 + 3]  = (unsigned char) 0xff;
					else
						teximage->data[ ix * 4 + 3]  = (unsigned char)  0xff - 
								teximage->data[ ix * 4 + 3];
					tmpa = (unsigned char) ((1.0 - bw_color) * 0xff);
				}
				/* make texture uniform b/w color */
				teximage->data[ ix * 4 + 0]  =
					(unsigned char) ( tmpa);
				teximage->data[ ix * 4 + 1]  =
 					(unsigned char) ( tmpa);
				teximage->data[ ix * 4 + 2]  =
 					(unsigned char) ( tmpa);
				/* negate alpha */
			}
	}
		
	if (blur > 0) {
		if (! anegative ) /* anegative alread b/w's the whole image */
			for (ix = 0 ; ix < teximage->height * teximage->width; ix++)
				if (!teximage->data[ ix * 4 + 3])
				{
					teximage->data[ ix * 4 + 0]  =
						(unsigned char) ( 255.0 * bw_color);
					teximage->data[ ix * 4 + 1]  =
 						(unsigned char) ( 255.0 * bw_color);
					teximage->data[ ix * 4 + 2]  =
 						(unsigned char) ( 255.0 * bw_color);
				}
		;
		tmpbuf = calloc(teximage->height * teximage->width * 4, sizeof(unsigned char)  )	;
		while (blur--) {
			/* zero out tmp alpha buffer */
			for (iy = 0 ; iy <teximage->height * teximage->width * 4 ; iy++)
			 	tmpbuf[iy] = 0;
			for (cchan = 0; cchan < 4 ; cchan++) {
				for (iy = 0 ; iy < teximage->height ; iy++) {
					for (ix = 0 ; ix < teximage->width ; ix++) {
						dtaidx = (teximage->width * iy + ix) * 4;
						tmpa =  teximage->data[dtaidx + cchan];
						tmpfa = (float) tmpa * boxdiv;
						/* box filter */
						for (by = -boxsize ; by <= boxsize; by++) {
							for (bx = -boxsize ; bx <= boxsize; bx++) {
								indx = wrapVal(ix + bx, 0, teximage->width);
								indy = wrapVal(iy + by, 0, teximage->height);
								tmpidx = (teximage->width * indy + indx) * 4;
								blursum = tmpfa;
								tmpbuf[tmpidx + cchan] += (unsigned char) blursum;
							} /* for bx */
						} /* for by  */
					} /* for ix  */
				} /* for iy */
			} /* for cchan */
			/* copy back buffer */
			for (ix = 0 ; ix < teximage->height * teximage->width * 4; ix++)
				teximage->data[ix] = tmpbuf[ix];
		} /*while blur */
		free(tmpbuf); /*tidy*/
	} /* if blur */

			
	

        clear_gl_error();
#ifdef HAVE_GLBINDTEXTURE
        glBindTexture(GL_TEXTURE_2D, texbind);
        clear_gl_error(); /* WTF? sometimes "invalid op" from glBindTexture! */
#endif
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, teximage->width, teximage->height,
                        0, GL_RGBA, GL_UNSIGNED_BYTE, teximage->data);
        check_gl_error("texture");
	setTexParams(); 
        XDestroyImage(teximage);
}
Exemplo n.º 13
0
int lcaFindMaxWeight(int v, int u)
{
    if(nodes[v].depth > nodes[u].depth)
    {
        int temp = v;
        v = u;
        u = temp;
    }

    int logValue = mylog2(tree.size()); 
    
    int maxWeight = 0;
    
    if(nodes[u].depth!=nodes[v].depth)
    {
        for(int i = logValue;i>=0;i--)
        {
            if(nodes[u].depth - nodes[v].depth>=(1<<i))
            {
                if(dpWeight[u][i]>maxWeight)
                {
                    maxWeight = dpWeight[u][i];
                }
           
                u=dp[u][i];
            }
        }
    }
    
    if(u==v) return maxWeight;
    
    int i;
    for(i = logValue;i>=0;--i)
    {
        if(dp[v][i]!=dp[u][i])
        {
            if(dpWeight[u][i]>maxWeight)
            {
                maxWeight = dpWeight[u][i];  
            }
            if(dpWeight[v][i]>maxWeight)
            {
                maxWeight = dpWeight[v][i];   
            }                        
            v = dp[v][i];
            u = dp[u][i];
            
            if(u==v)
            {
                return maxWeight;    
            }
        }
    }
        
    if(dpWeight[v][0]>maxWeight)        
    {
        maxWeight = dpWeight[v][0];    
    }
    if(dpWeight[u][0]>maxWeight)        
    {
        maxWeight = dpWeight[u][0];    
    }

    return maxWeight;   
}
Exemplo n.º 14
0
double H(size_t n, size_t k)
{
    double p = double(k) / n;
    double q = 1 - p;
    return p * mylog2(1 / p) + q * mylog2(1 / q);
}
Exemplo n.º 15
0
//
// not really sure how they're calculated in the actual game
// but they have to be measured in milliseconds. wouldn't make sense
// if it wasn't
//
static double usectotimecents(int usec)
{
    double t = (double)usec / 1000.0;
    return (1200 * mylog2(t));
}