#include "ell.h" #include "ell_conv.h" #include "stdlib.h" void computeEllRowLenghts( int *ellRowLengths, int *ellMaxRowSize, int rowsCount, int nonZerosCount, const int* cooRowIndices, int cooBaseIndex ) { // find the max number of non zero per row int maxRowSize = 0; int i; for (i=0; i maxRowSize) maxRowSize = currCount; } *ellMaxRowSize = maxRowSize; } int computeEllAllocPitch(int rowsCount) { // returns a pitch good for indices and values return ((rowsCount + 31)/32)*32; } void cooToEll( void *ellValues, int *ellIndices, int ellValuesPitch, int ellIndicesPitch, int ellMaxRowSize, int ellBaseIndex, int rowsCount, int nonZerosCount, const int* cooRowIndices, const int* cooColsIndices, const void* cooValues, int cooBaseIndex, spgpuType_t valuesType ) { size_t elementSize = spgpuSizeOf(valuesType); // fill values and indices int* currentPos = (int*)malloc(rowsCount*sizeof(int)); int i; for (i=0; i dstRs[j]) { app_dstRs[k] = dstRs[i]; app_rIdx[k] = rIdx[i]; ++k; ++i; } else { app_dstRs[k] = dstRs[j]; app_rIdx[k] = rIdx[j]; ++k; ++j; } } while (i<=center) { app_dstRs[k] = dstRs[i]; app_rIdx[k] = rIdx[i]; ++k; ++i; } while (j<=end) { app_dstRs[k] = dstRs[j]; app_rIdx[k] = rIdx[j]; ++k; ++j; } for (k=start; k<=end; k++) { dstRs[k] = app_dstRs[k-start]; rIdx[k] = app_rIdx[k-start]; } } void mergesort(int *dstRs, int *rIdx, int size) { int* app_dstRs = (int*)malloc(size*sizeof(int)); int* app_rIdx = (int*)malloc(size*sizeof(int)); int sizetomerge=size-1; size--; int i; int n=2; while (nsizetomerge) merge (app_dstRs, app_rIdx, dstRs, rIdx, sizetomerge -((sizetomerge)%n),sizetomerge,size,size); sizetomerge=sizetomerge-((sizetomerge+1)%n);} n=n*2; } if (size>sizetomerge) merge (app_dstRs, app_rIdx, dstRs,rIdx,0,size-(size-sizetomerge),size,size); free(app_dstRs); free(app_rIdx); } void ellToOell( int *rIdx, void *dstEllValues, int *dstEllIndices, int *dstRs, const void *srcEllValues, const int *srcEllIndices, const int *srcRs, int ellValuesPitch, int ellIndicesPitch, int rowsCount, spgpuType_t valuesType ) { size_t elementSize = spgpuSizeOf(valuesType); int i,j; for (i=0; i