コード例 #1
0
ファイル: uEZWAVFile.c プロジェクト: EnricoGiordano1992/Tesi
/*---------------------------------------------------------------------------*/
T_uezError UEZWAVChangeFile(char* newFile)
{
    T_uezError error;
    
    UEZTaskSuspend(G_playerTask);
    (*i2s)->Stop((void*)i2s);//UEZStopWAV();
    playStatus = EFalse;
    UEZFileClose(file);
    fileOpen = EFalse;
    error = UEZFileOpen(newFile, FILE_FLAG_READ_ONLY, &file);
    if(error != UEZ_ERROR_NONE)
        return error;
     fileOpen = ETrue;
    error = UEZFileRead(file, &throwAway, 44, &numBytesRead);
    readNextBlock(wav, &numBytesRead);
    readNextBlock(wav2, &numBytesRead2);
    read1 = 0;
    read2 = 0;
    index = 0;
    flag = ETrue;
    playStatus = ETrue;
    UEZTaskResume(G_playerTask);
    (*i2s)->Start((void*)i2s);
    return UEZ_ERROR_NONE;
}
コード例 #2
0
    int useTimeSlice()
    {
        if (isFullyLoaded())
        {
            if (reader != nullptr && source != nullptr)
                releaseResources();

            return -1;
        }

        bool justFinished = false;

        {
            const ScopedLock sl (readerLock);

            createReader();

            if (reader != nullptr)
            {
                if (! readNextBlock())
                    return 0;

                justFinished = true;
            }
        }

        if (justFinished)
            owner.cache.storeThumb (owner, hashCode);

        return timeBeforeDeletingReader;
    }
コード例 #3
0
ファイル: uEZWAVFile.c プロジェクト: EnricoGiordano1992/Tesi
/*---------------------------------------------------------------------------*/
T_uezError UEZWAVPlayFile(char* fileName)
{
    T_uezError error;
    
    error=UEZFileOpen(fileName, FILE_FLAG_READ_ONLY, &file);
    if(error != UEZ_ERROR_NONE)
        return error;
    fileOpen = ETrue;
    error = UEZFileRead(file, &throwAway, 44, &numBytesRead);
    readNextBlock(wav, &numBytesRead);
    readNextBlock(wav2, &numBytesRead2);
    read1 = 0;
    read2 = 0;
    index = 0;
    flag = ETrue;

    UEZTaskCreate((T_uezTaskFunction)UEZStartWAV, "Player", 4096, 0,
                UEZ_PRIORITY_NORMAL, &G_playerTask);
    return UEZ_ERROR_NONE;
}
コード例 #4
0
ファイル: uEZWAVFile.c プロジェクト: EnricoGiordano1992/Tesi
/*---------------------------------------------------------------------------*/
void UEZStartWAV()
{
  (*i2s)->Start((void*)i2s);
  playStatus = ETrue;

    while (numBytesRead != 0 && numBytesRead2 != 0)
    {
        UEZSemaphoreGrab(wavSem, UEZ_TIMEOUT_INFINITE);
        if (read1)
        {
            readNextBlock(wav, &numBytesRead);
            read1 = EFalse;
        }
        if (read2)
        {
            readNextBlock(wav2, &numBytesRead2);
            read2 = EFalse;
        }
    }
    UEZStopWAV();
}
コード例 #5
0
static void * readBinaryFile(void * args) {
	BinaryFileReaderData * data = (BinaryFileReaderData *) args;
	char * lastChrom = NULL;
	int lastStart = -1;
	bool pointByPoint = false;

	while (true)
		if (readNextBlock(data, &lastChrom, &lastStart, &pointByPoint))
			return NULL;

	return NULL;
}
コード例 #6
0
ファイル: PBFParser.cpp プロジェクト: NaWer/Project-OSRM
inline void PBFParser::ReadData() {
	bool keepRunning = true;
	do {
		_ThreadData *threadData = new _ThreadData();
		keepRunning = readNextBlock(input, threadData);

		if (keepRunning) {
			threadDataQueue->push(threadData);
		} else {
			threadDataQueue->push(NULL); // No more data to read, parse stops when NULL encountered
			delete threadData;
		}
	} while(keepRunning);
}
コード例 #7
0
void DsdiffFileReader::rewind()
{
	// position the file at the start of the data chunk
	if (file.seekg(sampleDataPointer)) {
		errorMsg = "dsfFileReader::rewind:file seek error";
	}
	allocateSampleBuffer();
	bufferCounter = 0;
	bufferMarker = 0;
	readNextBlock();
	bufferCounter = 0;
	posMarker = -1;
	clearBuffer();
}
コード例 #8
0
void DsfFileReader::rewind()
{
	// position the file at the start of the data chunk
	if (file.seekg(sampleDataPointer)) {
		errorMsg = "dsfFileReader::readFirstBlock:file seek error";
		return;
	}
	allocateBlockBuffer();
	blockCounter = 0;
	blockMarker = 0;
	readNextBlock();
	blockCounter = 0;
	posMarker = -1;
	clearBuffer();
	return;
}
コード例 #9
0
ファイル: PBFParser.cpp プロジェクト: fredj/osrm
inline void PBFParser::ReadData()
{
    bool keep_running = true;
    do
    {
        ParserThreadData *thread_data = new ParserThreadData();
        keep_running = readNextBlock(input, thread_data);

        if (keep_running)
        {
            thread_data_queue->push(thread_data);
        }
        else
        {
            // No more data to read, parse stops when nullptr encountered
            thread_data_queue->push(nullptr);
            delete thread_data;
        }
    } while (keep_running);
}
コード例 #10
0
bool DsdiffFileReader::step()
{
	bool ok = true;
	
	if (!samplesAvailable())
		ok = false;
	else if (bufferMarker>=sampleBufferLenPerChan)
		ok = readNextBlock();
	
	if (ok) {
		for (dsf2flac_uint16 i=0; i<chanNum; i++)
			circularBuffers[i].push_front(sampleBuffer[i+bufferMarker*chanNum]);
		bufferMarker++;
	} else {
		for (dsf2flac_uint16 i=0; i<chanNum; i++)
			circularBuffers[i].push_front(getIdleSample());
	}
	
	posMarker++;
	return ok;
}
コード例 #11
0
bool DsfFileReader::step()
{
	bool ok = true;
	
	if (!samplesAvailable())
		ok = false;
	else if (blockMarker>=blockSzPerChan)
		ok = readNextBlock();
	
	if (ok) {
		for (dsf2flac_uint32 i=0; i<chanNum; i++)
			circularBuffers[i].push_front(blockBuffer[i][blockMarker]);
		blockMarker++;
	} else {
		for (dsf2flac_uint32 i=0; i<chanNum; i++)
			circularBuffers[i].push_front(getIdleSample());
	}

	posMarker++;
	return ok;
}
コード例 #12
0
ファイル: juce_AudioThumbnail.cpp プロジェクト: Krewn/LIOS
    int useTimeSlice() override
    {
        if (isFullyLoaded())
        {
            if (reader != nullptr && source != nullptr)
            {
                if (Time::getMillisecondCounter() > lastReaderUseTime + timeBeforeDeletingReader)
                    releaseResources();
                else
                    return 200;
            }

            return -1;
        }

        bool justFinished = false;

        {
            const ScopedLock sl (readerLock);

            createReader();

            if (reader != nullptr)
            {
                if (! readNextBlock())
                    return 0;

                justFinished = true;
            }
        }

        if (justFinished)
            owner.cache.storeThumb (owner, hashCode);

        return 200;
    }
コード例 #13
0
ファイル: test_customize.c プロジェクト: jyang28/cs525
/* Try to create, open, and close a multi-page file */
void
testMultiPageContent(void)
{
  SM_FileHandle fh;
  SM_PageHandle ph;
  int i;

  testName = "test multi-page content";

  ph = (SM_PageHandle) malloc(PAGE_SIZE);

  // create a new page file
  TEST_CHECK(createPageFile (TESTPF));
  TEST_CHECK(openPageFile (TESTPF, &fh));
  printf("created and opened file\n");
  
  //ensure the capacity of the file with 4 pages
  TEST_CHECK(ensureCapacity(4,&fh));
  // read the current page into handle
  TEST_CHECK(readCurrentBlock(&fh, ph));
  // the page should be empty (zero bytes)
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == 0), "expected zero byte in current page of freshly initialized page");
  printf("current block was empty with the page number =%d\n", getBlockPos(&fh));
    
  // read the next page into handle
  TEST_CHECK(readNextBlock(&fh, ph));
  // the page should be empty (zero bytes)
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == 0), "expected zero byte in next page of freshly initialized page");
  printf("the next block was empty\n");
  printf("the updated page number is =%d\n",getBlockPos(&fh));
	
  // change ph to be a string and write that one to disk
  for (i=0; i < PAGE_SIZE; i++)
    ph[i] = (i % 10) + '0';
  TEST_CHECK(writeCurrentBlock(&fh, ph));
  printf("writing current block with the page number =%d\n", getBlockPos(&fh));

  // read back the page containing the string and check that it is correct
  TEST_CHECK(readCurrentBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  printf("reading back current block into memory with page number =%d\n", getBlockPos(&fh));
 
  // read the last page into handle
  TEST_CHECK(readLastBlock(&fh, ph));
  // the page should be empty (zero bytes)
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == 0), "expected zero byte in last page of freshly initialized page");
  printf("last block was empty with the page number =%d\n", getBlockPos(&fh));


  // change ph to be a string and write that one to disk
  for (i=0; i < PAGE_SIZE; i++)
    ph[i] = (i % 10) + '0';
  TEST_CHECK(writeCurrentBlock(&fh, ph));
  printf("writing current block with the page number =%d\n", getBlockPos(&fh));

  // read back the page containing the string and check that it is correct
  TEST_CHECK(readCurrentBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  printf("reading back current block into memory with page number =%d\n", getBlockPos(&fh));



  // destroy new page file
  TEST_CHECK(destroyPageFile (TESTPF));  
  
  TEST_DONE();
}
コード例 #14
0
/****************************************************************
 * Function Name: myTestAssign1
 *  
 * Description: Additional tests for Storage Manager.
 * 
 * Parameter: void
 * 
 * Return: void
 * 
 * Author: Dhruvit Modi ([email protected])
 *         Monika Priyadarshani ([email protected])
 ****************************************************************/
void
myTestAssign1(void)
{
  SM_FileHandle fh;
  SM_PageHandle ph;
  int i;
  
  ph = (SM_PageHandle) malloc(PAGE_SIZE);

  // create a new page file
  TEST_CHECK(createPageFile (TESTPF));
  TEST_CHECK(openPageFile (TESTPF, &fh));
  printf("created and opened file\n");
  
    
  for (i=0; i < PAGE_SIZE; i++)
    ph[i] = (i % 10) + '0';
  
  // write on the first block  
  TEST_CHECK(writeCurrentBlock (&fh, ph));
  printf("writing first block\n");
  
  // append empty block
  TEST_CHECK(appendEmptyBlock(&fh));
  printf("append Empty block\n");
   
   // write on the second block 
  TEST_CHECK(writeBlock (1, &fh, ph));
  printf("writing second block\n");
  
  TEST_CHECK(appendEmptyBlock(&fh));
  printf("append Empty block\n");
  
    // write to the third block
  TEST_CHECK(writeBlock (2, &fh, ph));
  printf("writing third block\n");
  
  // read back the page containing the string and check that it is correct
  printf("reading first block\n");
  TEST_CHECK(readFirstBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  
  
  // read back the page containing the string and check that it is correct
  printf("reading last block\n");
  TEST_CHECK(readLastBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  
  
  // read back the page containing the string and check that it is correct
  printf("reading previous block\n");
  TEST_CHECK(readPreviousBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  
  
  // read back the page containing the string and check that it is correct
  printf("reading current block\n");
  TEST_CHECK(readCurrentBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  
  
  // read back the page containing the string and check that it is correct
  printf("reading next block\n");
  TEST_CHECK(readNextBlock (&fh, ph));
  for (i=0; i < PAGE_SIZE; i++)
    ASSERT_TRUE((ph[i] == (i % 10) + '0'), "character in page read from disk is the one we expected.");
  
  // append empty block
  TEST_CHECK(appendEmptyBlock(&fh));
  printf("append Empty block\n");
  
  // ensure capacity
  TEST_CHECK(ensureCapacity(6, &fh));
  printf("ensure capacity\n");
  
    // destroy new page file
  TEST_CHECK(destroyPageFile (TESTPF));  
  
  TEST_DONE();
}
コード例 #15
0
/* Test program 
 * created 23/09/2014
 * author Alex Bombrun
 * 
 * icc -O1  -o eigen.exe lapackReadStore.c mpiutil.c normals.c matrixBlockStore.c -mkl
 * ./eigen.exe 4 4
 *
 */
int main(int argc, char **argv) {
  
    FILE* store;
    FILE* scaStore;
    
    int N , M;
    int i, j;
    
    int n_blocks;
    int scalapack_size;
    int NB, MB;
    int i_block, j_block;
    int dim[4];
    double * mat;  // local matrix block use for reading
    
    double * matK; // the kernel matrix ng x 6
        
    int t, t_block;
    
    const char* profileG_file_name= "./data/NormalsG/profile.txt";
    const char* store_location = "./data/ReducedNormals";
    const char* scaStore_location ="./data/CholeskyReducedNormals";
    const char* kernel_file_name ="./data/kernel.txt";
    
    int mp;	 // number of rows in the processor grid
    int mla;   // number of rows in the local array
    int mb;    // number of rows in a block
    int np;	 // number of columns in the processor grid
    int nla;   // number of columns in the local array
    int nb;    // number of columns in a block
    
    int mype,npe; // rank and total number of process
    
    int idescal[9]; // matrix descriptors
    double *la; // matrix values: al is the local array
    
    int idescaal[9];
    double *laa;
    
    int idescbl[9];
    double *lb;
    double normb;
    
    int idescxl[9];
    double *lx;
    double normx;

    int idesck1l[9];
    double *lk1;
    double normk1;
    
    int idesczl[9]; // matrix descriptors
    double *lz; // matrix values: al is the local array
    
    double *w;
   
    int ierr; // error output 
    int mp_ret, np_ret, myrow, mycol; // to store grid info
    
    int zero=0; // value used for the descriptor initialization
    int one=1; // value used for the descriptor initialization
    
    int  m,n; // matrix A dimensions
    double norm, cond;
    double *work = NULL;
    double * work2 = NULL;
    int *iwork = NULL;
    int lwork, liwork;


     float ll,mm,cr,cc;
      int ii,jj,pr,pc,h,g; // ii,jj coordinates of local array element
      int rsrc=0,csrc=0; // assume that 0,0 element should be stored in the 0,0 process
      int n_b = 1;
      int index;
    int icon; // scalapack cblacs context
    char normJob, jobz, uplo, trans, notrans, diag;
    
    double MPIt1, MPIt2, MPIelapsed;
    
    jobz= 'N'; uplo='U';
    Cblacs_pinfo( &mype, &npe );
    
     if (argc == 3) {
	//printf("%s %s %s\n", argv[0], argv[1], argv[2]);
	n_blocks= (int) strtol(argv[1], NULL, 10);
	scalapack_size= (int) strtol(argv[2], NULL, 10);
     } else {
	printf("Usage: expect 2 integers \n");
	printf(" 1 : the number of diagonal blocks \n");
	printf(" 2 : scalapack number to define block size (assume n is divisible by sqrt(p) and that n/sqrt(p) is divisible by this number)\n");
	exit( -1);
     }
    
  

    printf("%d/%d: read store\n",mype,npe);
   
    N = getNumberOfLine(profileG_file_name); // the dimension of the matrix;
    M = N; // square matrix
    
    m=M; //mla*mp;
    n=N; //nla*np;
   
    np = isqrt(npe); // assume that the number of process is a square
    mp = np; // square grid
    
    mla = m/mp; // assume that the matrix dimension if a multiple of the process grid dimension
    nla = n/np;
    
    mb = mla/scalapack_size; // assume that the dimension of the matrix is a multiple of the number of the number of diagonal blocks
    nb = nla/scalapack_size;
    
    // init CBLACS
    Cblacs_get( -1, 0, &icon );
    Cblacs_gridinit( &icon,"c", mp, np ); 
    Cblacs_gridinfo( icon, &mp_ret, &np_ret, &myrow, &mycol);
    
   
    // read blocks and set the reduced normal matrix in scalapack grid
    // allocate local matrix
    la=malloc(sizeof(double)*mla*nla);
    printf("%d/%d: full matrix (%d,%d), local matrix (%d,%d), processor grid (%d,%d), block (%d,%d) \n", mype, npe, m, n, mla, nla, np, mp, mb, nb);
    
    for(i_block=0;i_block<n_blocks;i_block++){
      printf("%d/%d: process store block %d \n", mype, npe, i_block);
      readStore(&store,i_block,store_location);
      t_block = 0;
      while(readNextBlockDimension(dim,store)!=-1) { // loop B over all block tasks
	j_block = mpi_get_diag_block_id(i_block, t_block, n_blocks);
	mat = malloc((dim[1]-dim[0])*(dim[3]-dim[2]) * sizeof(double));         
	readNextBlock(dim[0],dim[1],dim[2],dim[3],mat,store);
//	printf("%d/%d: read block (%d,%d) with global indices (%d,%d,%d,%d) \n",mype, npe, i_block,j_block,dim[0],dim[1],dim[2],dim[3]);
	
	NB = dim[1]-dim[0];
	MB = dim[3]-dim[2];
	for(i = dim[0];i<dim[1];i++){
	  for(j = dim[2];j<dim[3];j++){
	      //matA[i*M+j] = mat[(i-dim[0])*MB+(j-dim[2])];
	     // finding out which pe gets this i,j element
              cr = (float)( i/mb );
              h = rsrc+(int)(cr);
              pr = h%np;
              cc = (float)( j/mb );
              g = csrc+(int)(cc);
              pc = g%mp;
	      // check if process should get this element
              if (myrow == pr && mycol==pc){
		  // ii = x + l*mb
		  // jj = y + m*nb
                  ll = (float)( ( i/(np*mb) ) );  // thinks seems to be mixed up does not matter as long as the matrix, the block and the grid is symmetric
                  mm = (float)( ( j/(mp*nb) ) );
                  ii = i%mb + (int)(ll)*mb;
                  jj = j%nb + (int)(mm)*nb;
                  index=jj*mla+ii;   // seems to be the transpose !?
		  //if(index<0) printf("%d/%d: negative index (%d,%d) \n",mype,npe,i,j);
		  //if(index>=mla*nla) printf("%d/%d: too large index (%d,%d) \n",mype,npe,i,j);
                  la[index] = mat[(i-dim[0])*MB+(j-dim[2])];
              }
	  }
	}
	// transpose
	if(j_block != i_block){
	  for(i = dim[0];i<dim[1];i++){
	    for(j = dim[2];j<dim[3];j++){
	      //matA[j*M+i] = mat[(i-dim[0])*MB+(j-dim[2])];
	       // finding out which pe gets this j,i element
              cr = (float)( j/mb );
              h = rsrc+(int)(cr);
              pr = h%np;
              cc = (float)( i/mb );
              g = csrc+(int)(cc);
              pc = g%mp;
	      // check if process should get this element
              if (myrow == pr && mycol==pc){
		  // ii = x + l*mb
		  // jj = y + m*nb
                  ll = (float)( ( j/(np*mb) ) );  // thinks seems to be mixed up does not matter as long as the matrix, the block and the grid is symmetric
                  mm = (float)( ( i/(mp*nb) ) );
                  ii = j%mb + (int)(ll)*mb;
                  jj = i%nb + (int)(mm)*nb;
                  index=jj*mla+ii;   // seems to be the transpose !?
		  //if(index<0) printf("%d/%d: negative index (%d,%d) \n",mype,npe,i,j);
		  //if(index>=mla*nla) printf("%d/%d: too large index (%d,%d) \n",mype,npe,i,j);

                  la[index] = mat[(i-dim[0])*MB+(j-dim[2])];
              }
	    }
	  } 
	}
	
	free(mat);
	t_block++;
      }
      closeStore(store);
    }
    
    
    printf("%d/%d: finished scaterring the matrix \n",mype,npe);
    
    
    // read the kernel matrix
    printf("%d/%d: set kernel \n",mype,npe);
    matK = malloc(N * 6*  sizeof(double));
    readMatrixDouble(matK,kernel_file_name);
    
    // set k1
    lk1 = calloc(sizeof(double),mla);
    
    for(i = 0; i<N; i++) {
        // finding out which pe gets i element
        cr = (float)( i/mb );
        h = rsrc+(int)(cr);
        pr = h%np;
        // check if process should get this element
        if (myrow == pr) {
            // ii = x + l*mb
            ll = (float)( ( i/(np*mb) ) );  // thinks seems to be mixed up does not matter as long as the matrix, the block and the grid is symmetric
            ii = i%mb + (int)(ll)*mb;
            lk1[ii] = matK[N*0+i];
        }
    }
    printf("%d/%d: finished scaterring the kernel vector \n",mype,npe);
   			    
			    
    
    printf("%d/%d: start computing \n",mype,npe);
       // set the matrix descriptor
    ierr=0;
    descinit_(idescal, &m, &n  , &mb, &nb , &zero, &zero, &icon, &mla, &ierr); // processor grip id start at 0
    if (mype==0) saveMatrixDescriptor(idescal, scaStore_location);
  
    ierr=0;
    descinit_(idescaal, &m, &n  , &mb, &nb , &zero, &zero, &icon, &mla, &ierr); // processor grip id start at 0
  
    
    ierr=0;
    descinit_(idescbl, &m, &one  , &mb, &nb , &zero, &zero, &icon, &nla, &ierr); // processor grip id start at 0
    lb = calloc(sizeof(double),mla);
    
    ierr=0;
    // set x
    descinit_(idescxl, &n, &one  , &mb, &nb , &zero, &zero, &icon, &nla, &ierr); // processor grip id start at 0
    lx = calloc(sizeof(double),mla);
    for(i=0;i<mla;i++){
      lx[i] = 1.0/m;
    }
    pddot_(&n,&normx,lx,&one,&one,idescxl,&one,lx,&one,&one,idescxl,&one); // normx <- x'x
    if (mype==0) printf("%d/%d: normx2 %E \n",mype,npe,normx);  
    
    ierr=0;
    // set k1
    descinit_(idesck1l, &n, &one  , &mb, &nb , &zero, &zero, &icon, &nla, &ierr); // processor grip id start at 0
    pddot_(&n,&normk1,lk1,&one,&one,idesck1l,&one,lk1,&one,&one,idesck1l,&one); // normx <- x'x
    if (mype==0) printf("%d/%d: normk1 square %E \n",mype,npe,normk1);  
    
    
    
    ierr=0;
    // set b
    double alpha =1.0;
    double beta =0.0;
    notrans = 'N';
    pdgemv_(&notrans,&m,&n,&alpha,la,&one,&one,idescal,lk1,&one,&one,idesck1l,&one,&beta,lb,&one,&one,idescbl,&one); // b <- A k1
    pddot_(&n,&normb,lb,&one,&one,idescbl,&one,lb,&one,&one,idescbl,&one); // norm <- b'b
    if (mype==0) printf("%d/%d: is kernel, normb square %E \n",mype,npe,normb); 

    
    ierr=0;
    // set b
    alpha =1.0;
    beta =0.0;
    notrans = 'N';
    pdgemv_(&notrans,&m,&n,&alpha,la,&one,&one,idescal,lx,&one,&one,idescxl,&one,&beta,lb,&one,&one,idescbl,&one); // b <- A x
    pddot_(&n,&normb,lb,&one,&one,idescbl,&one,lb,&one,&one,idescbl,&one); // norm <- b'b
    if (mype==0) printf("%d/%d: normb2 %E \n",mype,npe,normb);  
   
    
    // set aa
    printf("%d/%d: start setting aa with k1 x k1\' \n",mype,npe);
  
    alpha = 1.0;
    beta = 1.0;
    trans = 'T';
    notrans = 'N';
    // laa=malloc(sizeof(double)*mla*nla); // for debugging
    //pdgemm(transa, transb, 
    //		m, n, k, 
    //		alpha, a, ia , ja , desca, 
    //		b, ib , jb ,descb, 
    //		beta, c, ic , jc , descc)
    // A = k1 (Nx1)
    // B = k1 (Nx1)
    // C = aa (MxN)  ... M=N
    // C <- C + A x B'    
    pdgemm_(&notrans, &trans,
                   &N, &N, &one,
                   &alpha, lk1, &one, &one, idesck1l,
		   lk1, &one, &one, idesck1l,
                   &beta,  la, &one, &one, idescal );
      
    
    for(j = 1; j<6; j++) {
        for(i = 0; i<N; i++) {
            // finding out which pe gets i element
            cr = (float)( i/mb );
            h = rsrc+(int)(cr);
            pr = h%np;
            // check if process should get this element
            if (myrow == pr) {
                // ii = x + l*mb
                ll = (float)( ( i/(np*mb) ) );  // thinks seems to be mixed up does not matter as long as the matrix, the block and the grid is symmetric
                ii = i%mb + (int)(ll)*mb;
                lk1[ii] = matK[N*j+i];
            }
        }
         pdgemm_(&notrans, &trans,
                   &N, &N, &one,
                   &alpha, lk1, &one, &one, idesck1l,
		   lk1, &one, &one, idesck1l,
                   &beta,  la, &one, &one, idescal );
    }
    
    ierr = 0;
    // compute norm 1 of the reduced normal matrix
    /* DO NOT WORK
    lwork = 2*mla+2*nla;
    work = malloc(sizeof(double)*lwork);
    normJob = '1';
    norm = pdlansy_(&normJob, &uplo, &n, la, &one, &one, idescal, work);  // matrix index start at one 
    printf("%d/%d: norm %f \n",mype,npe,norm);
    free(work);
    */
    
    ierr = 0;
    // compute the cholesky decomposition 
    printf("%d/%d: start computing cholesky factor\n",mype,npe);  
    pdpotrf_(&uplo,&n,la,&one,&one,idescal,&ierr);
    printf("%d/%d: finish computing cholesky factor\n",mype,npe);
    openScalapackStore(&scaStore,myrow,mycol,scaStore_location);
    saveLocalMatrix(la,nla,mla,scaStore);
    
    double test=0.0;
    for(i=0;i<nla*mla;i++){
	test += la[i]*la[i];
    }
    printf("%d/%d: finished computing cholesky, test=%f \n",mype,npe,test);
    
    ierr =0;
    // assume x and b set
    // assume cholesky decomposition
    // compute the soluation A x = b
    diag = 'N';
    printf("%d/%d: start solving\n",mype,npe);  
    //pdpptrs_(&uplo, &trans , &diag , &n , &one , la , &one , &one , idescal , lb , &one , &one , idescbl , &ierr); // solve triangular system
    //pdtrtrs (&uplo, &trans , &diag , &n , &n , la , &one , &one , idescal , lb , &one , &one , idescbl , &ierr);
    pdpotrs_(&uplo, &n , &one , la , &one , &one , idescal , lb , &one , &one , idescbl , &ierr); // b<- A-1 b
    
    alpha = -1.0;
    normb=0;
    pdaxpy_(&n,&alpha,lx,&one,&one,idescxl,&one,lb,&one,&one,idescbl,&one); // b<-b-x
    pddot_(&n,&normb,lb,&one,&one,idescbl,&one,lb,&one,&one,idescbl,&one); // norm <- b'b
    if (mype==0) printf("%d/%d: finish solving, norm2(sol-true) %E \n",mype,npe,normb);  
    
    

    ierr = 0;
    /*
    // compute the eigen values
    jobz= 'N'; uplo='U'; // with N z is ignored
    descinit_(idesczl, &m, &n  , &mb, &nb , &zero, &zero, &icon, &mla, &ierr);
    lz = malloc(sizeof(double)*mla*nla);
    w = malloc(sizeof(double)*m);
    lwork = -1;
    work = malloc(sizeof(double)*2);
    pdsyev_( &jobz, &uplo, &n, la, &one, &one, idescal, w, lz, &one, &one, idesczl, work, &lwork, &ierr);   // only compute lwork
    //pdsyev_( &jobz, &uplo, &n, A, &ione, &ione, descA, W, Z, &ione, &ione, descZ, work, &lwork, &info );
    lwork= (int) work[0];
    free(work);
    work = (double *)calloc(lwork,sizeof(double)) ;
    //MPIt1 = MPI_Wtime();
    pdsyev_( &jobz, &uplo, &n, la, &one, &one, idescal, w, lz, &one, &one, idesczl, work, &lwork, &ierr);   // compute the eigen values
    //MPIt2 = MPI_Wtime();
    //MPIelapsed=MPIt2-MPIt1;
    
    if (mype == 0) {
	saveMatrix(n,w,"eigenvalues.txt");
	//printf("%d/%d: finished job in %8.2fs\n",mype,npe,MPIelapsed); // not working
    }
    */
    
    ierr = 0;
    // compute the conditioner number assume that the norm and the cholesky decomposition have been computed
    /* DO NOT WORK
    lwork = 2*mla+3*nla;
    printf("%d/%d: lwork=%d @%p\n",mype,npe,lwork,&lwork);
    work2 = malloc(sizeof(double)*lwork);
    liwork = 2*mla+3*nla;
    iwork = malloc(sizeof(int)*liwork);
    pdpocon_(&uplo,&n,la,&one,&one,idescal,&norm,&cond,work2,&lwork,iwork,&liwork,&ierr);
    printf("%d/%d: condition number %f \n",mype,npe,cond);
    */
    
    free(la);
    Cblacs_gridexit(icon);
    Cblacs_exit( 0 );
    return 0;
}
コード例 #16
0
void testReadWrite(void) {
	SM_FileHandle fh;
	SM_PageHandle ph;

	int i;

	ph = (SM_PageHandle) malloc(PAGE_SIZE);

	testName = "test read and write methods";

	TEST_CHECK(createPageFile (TESTPF));

	TEST_CHECK(openPageFile (TESTPF, &fh));
	ASSERT_TRUE(strcmp(fh.fileName, TESTPF) == 0, "filename correct");
	ASSERT_TRUE((fh.totalNumPages == 1), "expect 1 page in new file");
	ASSERT_TRUE((fh.curPagePos == 0), "freshly opened file's page position should be 0");

	//Writes A, B, C, D, E, F, G, H from 0th page to 7th page
	for(i = 0; i < 8; i ++) {
		memset(ph, 'A' + i, PAGE_SIZE);
		TEST_CHECK(writeBlock (i, &fh, ph));
		printf("writing %d th block\n", fh.curPagePos);
	}

	// read first page into handle  i.e. A
	TEST_CHECK(readFirstBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++)
		ASSERT_TRUE((ph[i] == 'A'), "expected A");
	printf("first block contains A\n");

	// read last page into handle   i.e. H
	TEST_CHECK(readLastBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++)
		ASSERT_TRUE((ph[i] == 'H'), "expected H");
	printf("last block contains H\n");

	// read first page into handle  i.e. A
	readFirstBlock (&fh, ph);

	// read next page into handle   i.e. B
	TEST_CHECK(readNextBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++)
		ASSERT_TRUE((ph[i] == 'B'), "expected B");
	printf("block contains B\n");

	readNextBlock (&fh, ph);        //C
	readNextBlock (&fh, ph);        //D

	// read previous page into handle	i.e. C
	TEST_CHECK(readPreviousBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++)
		ASSERT_TRUE((ph[i] == 'C'), "expected C");
	printf("block contains C\n");

	readNextBlock (&fh, ph);        //D
	readNextBlock (&fh, ph);        //E

	// read current page into handle       i.e. E
	TEST_CHECK(readCurrentBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++)
		ASSERT_TRUE((ph[i] == 'E'), "expected E");
	printf("block contains E\n");

	readPreviousBlock (&fh, ph);        //D

	//Replace D with Z
	memset(ph, 'Z', PAGE_SIZE);
	TEST_CHECK(writeCurrentBlock (&fh, ph));
	printf("writing D with Z\n");

	// read current page into handle        i.e. Z
	TEST_CHECK(readCurrentBlock (&fh, ph));
	for (i=0; i < PAGE_SIZE; i++){
		ASSERT_TRUE((ph[i] == 'Z'), "expected Z");
	}
	printf("block contains Z\n");

	TEST_CHECK(closePageFile (&fh));
	TEST_CHECK(destroyPageFile (TESTPF));

	free(ph);


	TEST_DONE();
}
コード例 #17
0
    int GalacticusReader::getNextRow() {
        //assert(fileStream.is_open());

        DataBlock b;
        string name;
        string outputName;

        // get one line from already read datasets (using readNextBlock)
        // use readNextBlock to read the next block of datasets if necessary
        if (currRow == 0) {
            // we are at the very beginning
            // read block for given snapnum or start reading from 1. block

            if (user_snapnums.size() > 0) {
                current_snapnum = user_snapnums[countSnap];
                // check, if this snapnum really exists in outputMetaMap

                it_outputmap = outputMetaMap.find(current_snapnum);
                while (it_outputmap == outputMetaMap.end() && countSnap < numOutputs) {
                    cout << "Skipping snapnum " << current_snapnum << " because no corresponding output-group was found." << endl;
                    countSnap++;
                    current_snapnum = user_snapnums[countSnap];
                    it_outputmap = outputMetaMap.find(current_snapnum);
                }
                if (it_outputmap == outputMetaMap.end()) {
                    return 0;
                }
                outputName = (it_outputmap->second).outputName;
            } else {
                current_snapnum = it_outputmap->first;
                outputName = (it_outputmap->second).outputName;
            }

            // get corresponding output name
            //outputName = outputMetaMap[current_snapnum].outputName;

            nvalues = readNextBlock(outputName);
            countInBlock = 0;

        } else if (countInBlock == nvalues-1) {
            // end of data block/start of new one is reached!
            // => read next datablocks (for next output number)
            //cout << "Read next datablock!" << endl;

            // check if we are at the end
            //if (it_outputmap == outputMetaMap.end() || countSnap == user_snapnums.size()) {
            //    return 0;
            //}
            if (countSnap == numOutputs-1) {
                return 0;
            }

            // if we end up here, we should read the next block
            if (user_snapnums.size() > 0) {
                countSnap++;
                current_snapnum = user_snapnums[countSnap];
                // check, if this snapnum really exists in outputMetaMap

                it_outputmap = outputMetaMap.find(current_snapnum);
                while (it_outputmap == outputMetaMap.end() && countSnap < numOutputs) {
                    cout << "Skipping snapnum " << current_snapnum << " because no corresponding output-group was found." << endl;
                    countSnap++;
                    current_snapnum = user_snapnums[countSnap];
                    it_outputmap = outputMetaMap.find(current_snapnum);
                }
                if (it_outputmap == outputMetaMap.end()) {
                    return 0;
                }
                outputName = (it_outputmap->second).outputName;
            } else {
                it_outputmap++;

                // check, if we haven't reached the end yet
                if (it_outputmap == outputMetaMap.end()) {
                    cout << "End of outputs group is reached." << endl;
                    return 0;
                }

                current_snapnum = it_outputmap->first;
                outputName = (it_outputmap->second).outputName;
            }

            // get corresponding output name -- already done
            // outputName = outputMetaMap[current_snapnum].outputName;

            nvalues = readNextBlock(outputName);
            countInBlock = 0;

        } else {
            countInBlock++;
        }

        currRow++; // counts all rows

        // stop reading/ingesting, if mass is lower than threshold?
        // stop after reading maxRows?
    
        return 1;
    }
コード例 #18
0
ファイル: fastalib.c プロジェクト: ParaSky/cops
unsigned char *
nextSeq (FASTA_LIB *lib, int *length)
{
    int inx;
    int size;
    int done;
    int len;

    char *name = lib->seqName;
    unsigned char *seq = lib->seqBuffer;

    /* check if we are at the end of the library */
    if (lib->size == 0) {
        *length = 0;
        return NULL;
    }

    if (lib->pos == lib->size) {
        readNextBlock (lib);
    }

    inx = lib->pos;

    /* check for the start of a sequence */
    if (lib->readBuffer[inx] != '>') {
        fprintf (stderr, "Error parsing fasta file expecting > found %c\n",
            lib->readBuffer[inx]);
        exit (-1);
    }

    ++inx;

    /* read in the sequence name */
    len = 0;
    done = 0;
    do {
        if (inx >= lib->size) {
            size = readNextBlock (lib);
            if (size == 0) {
                *length = 0;
                return NULL;
            }
            inx = lib->pos;
        } else if (lib->readBuffer[inx] == '\n') {
            *name = '\0';
            done = 1;
        } else if (len < SEQ_NAME_SIZE - 1) {
            *name++ = lib->readBuffer[inx];
            len++;
        }
        ++inx;
    } while (!done);

    lib->pos = inx;

    /* read in the sequence */
    len = 0;
    done = 0;
    do {
        if (inx >= lib->size) {
            size = readNextBlock (lib);
            if (size == 0) {
                *seq = '\0';
                done = 1;
            }
            inx = 0;
        } else if (isspace(lib->readBuffer[inx])) {
            ++inx;
        } else if (lib->readBuffer[inx] == '>') {
            *seq = '\0';
            done = 1;
        } else if (len >= MAX_SEQ_LENGTH) {
            fprintf (stderr, "Sequence %s exceeds maximum length\n", 
                lib->seqName);
            exit (-1);
        } else {
            int value = AMINO_ACID_VALUE[lib->readBuffer[inx]];
            if (value == -1) {
                fprintf (stderr, "Unknown amino acid %c in sequence %s\n",
                    lib->readBuffer[inx], lib->seqName);
                exit (-1);
            }
            *seq++ = (char) value;
            inx++;
            len++;
        }
    } while (!done);

    lib->pos = inx;
    *length = len;

    lib->sequences++;
    lib->residues += len;

    /*  check if we need to pad the sequence to a multiple of 16  */
    if (lib->pad) {
        inx = 16 - (len % 16);
        while (inx--) {
            *seq++ = ALPHA_SIZE;
        }
        *seq = '\0';
    }

    return lib->seqBuffer;
}