Example #1
0
int main(int argc, char **argv) {

	int usemenu = parsecmdline(argc, argv);//./server port -i -n -l

	short unsigned int key[3];
	key[0] = getpid();
	key[1] = time(NULL);
	seed48(key);
			
    serverdata_type *s = readinput(inputfile, sdata);//read server.dat or saved-data to initiate dU* and p*

	pthread_t thread;
	if (usemenu) {int pthread_id = pthread_create(&thread, NULL, runmenu, (void *)s);
	//printf("pthread_id=%d\n",pthread_id);
	}
	int socket = bindsocket(port);
	//printf("socket=%d\n",socket);

	if (!usemenu) printf("No menu will be available\n");
	initparameters(s);
	//printf("key = %d\n", s->key);
// main loop - we read requests and complete transactions
	while (FOREVER_EVER_EVER) {
		//printf("entering loop\n");
		processrequest(socket, s);
		//printf("finishing loop\n");
	}

	return 0;

}
int main ( int argc, char *argv[] )

/******************************************************************************/
/*
  Purpose:
 
    MAIN is the main program for the star discrepancy bound computation.

  Modified:

    30 September 2003

  Reference:
 
    Eric Thiemard,
    An Algorithm to Compute Bounds for the Star Discrepancy,
    Journal of Complexity,
    Volume 17, pages 850-880, 2001.
*/
{
  int i;
  int j;
  double *oalpha;
  double *obeta;
  
  initparameters(argc,argv);
  readfile(argv[4]);

  printf("x={\n");
  for (i=0;i<taille;i++)
    {
      printf(" (");
      for (j=0;j<s;j++)
  	printf(" %f",points[i][j]);
      printf(" )\n");
    }
  printf("}\n\n");
  supertree();
  initlex();
  
  oalpha = (double *) calloc((unsigned) s,sizeof(double));
  obeta  = (double *) calloc((unsigned) s,sizeof(double));
  for (i=0;i<s;i++)
    obeta[i] = 1.0;

  decomposition(oalpha,obeta,0,1.0);

  printf("s=%d, epsilon=%f, n=%d\n",s,p,taille);
  printf("D_n^*(x) between %.10f and %.10f\n",borneinf,borne);

  return 0;
}
void MLFitterGSL::initfitter(){
    //do first whatever the fitter wants to do here
    Fitter::initfitter();

  #ifdef FITTER_DEBUG
  std::cout <<"mlfitter_gsl::initfitter called\n";
  #endif

  //createmodelinfo(); //update number of free parameters etc if a model has changed
  const int n=modelptr->getnpoints();
  try{
    //delete old solver and create new one
    if (solver!=0) gsl_multifit_fdfsolver_free (solver);
    const gsl_multifit_fdfsolver_type * T = gsl_multifit_fdfsolver_lmsder; //Scaled Levenberg Marquardt
    solver= gsl_multifit_fdfsolver_alloc (T,n,modelptr->getnroffreeparameters());

    //reallocate memory for parameter vector x and covariance matrix covar
    if (initialparameters!=0) gsl_vector_free (initialparameters);
    if (covar!=0) gsl_matrix_free (covar);

    initialparameters=gsl_vector_calloc (modelptr->getnroffreeparameters()); //allocate space for vector x, containing param values
    covar=gsl_matrix_calloc (modelptr->getnroffreeparameters(), modelptr->getnroffreeparameters());

    //init the link with the function to be fitted
    initfdf();

    //load the current parameters in the x vector
    initparameters();

    //reinit the solver
    gsl_multifit_fdfsolver_set(solver,&f,initialparameters);
  }
  catch(...){
    //problems with memory? -> kill this
    Saysomething mysay(0,"Error","Unable to allocate memory, exit MLFitterGSL",true);
    delete(this);
  }
}
Example #4
0
void SUBnote::setup(float freq,
                    float velocity,
                    int portamento_,
                    int midinote,
                    bool legato)
{
    this->velocity = velocity;
    portamento  = portamento_;
    NoteEnabled = ON;
    volume      = powf(0.1f, 3.0f * (1.0f - pars.PVolume / 96.0f)); //-60 dB .. 0 dB
    volume     *= VelF(velocity, pars.PAmpVelocityScaleFunction);
    if(pars.PPanning != 0)
        panning = pars.PPanning / 127.0f;
    else
        panning = RND;
    if(!legato) {
        numstages = pars.Pnumstages;
        stereo    = pars.Pstereo;
        start     = pars.Pstart;
        firsttick = 1;
    }
    int pos[MAX_SUB_HARMONICS];

    if(pars.Pfixedfreq == 0)
        basefreq = freq;
    else {
        basefreq = 440.0f;
        int fixedfreqET = pars.PfixedfreqET;
        if(fixedfreqET) { //if the frequency varies according the keyboard note
            float tmp = (midinote - 69.0f) / 12.0f
                * (powf(2.0f, (fixedfreqET - 1) / 63.0f) - 1.0f);
            if(fixedfreqET <= 64)
                basefreq *= powf(2.0f, tmp);
            else
                basefreq *= powf(3.0f, tmp);
        }
    }
    int BendAdj = pars.PBendAdjust - 64;
    if (BendAdj % 24 == 0)
        BendAdjust = BendAdj / 24;
    else
        BendAdjust = BendAdj / 24.0f;
    float offset_val = (pars.POffsetHz - 64)/64.0f;
    OffsetHz = 15.0f*(offset_val * sqrtf(fabsf(offset_val)));
    float detune = getdetune(pars.PDetuneType,
                             pars.PCoarseDetune,
                             pars.PDetune);
    basefreq *= powf(2.0f, detune / 1200.0f); //detune
//    basefreq*=ctl.pitchwheel.relfreq;//pitch wheel

    //global filter
    GlobalFilterCenterPitch = pars.GlobalFilter->getfreq() //center freq
                              + (pars.PGlobalFilterVelocityScale / 127.0f
                                 * 6.0f)                                           //velocity sensing
                              * (VelF(velocity,
                                      pars.PGlobalFilterVelocityScaleFunction)
                                 - 1);

    if(!legato) {
        GlobalFilterL = NULL;
        GlobalFilterR = NULL;
        GlobalFilterEnvelope = NULL;
    }

    int harmonics = 0;

    //select only harmonics that desire to compute
    for(int n = 0; n < MAX_SUB_HARMONICS; ++n) {
        if(pars.Phmag[n] == 0)
            continue;
        pos[harmonics++] = n;
    }
    if(!legato)
        firstnumharmonics = numharmonics = harmonics;
    else {
        if(harmonics > firstnumharmonics)
            numharmonics = firstnumharmonics;
        else
            numharmonics = harmonics;
    }


    if(numharmonics == 0) {
        NoteEnabled = OFF;
        return;
    }


    if(!legato) {
        lfilter = memory.valloc<bpfilter>(numstages * numharmonics);
        if(stereo)
            rfilter = memory.valloc<bpfilter>(numstages * numharmonics);
    }

    //how much the amplitude is normalised (because the harmonics)
    float reduceamp = 0.0f;

    for(int n = 0; n < numharmonics; ++n) {
        float freq =  basefreq * pars.POvertoneFreqMult[pos[n]];
        overtone_freq[n] = freq;
        overtone_rolloff[n] = computerolloff(freq);

        //the bandwidth is not absolute(Hz); it is relative to frequency
        float bw =
            powf(10, (pars.Pbandwidth - 127.0f) / 127.0f * 4) * numstages;

        //Bandwidth Scale
        bw *= powf(1000 / freq, (pars.Pbwscale - 64.0f) / 64.0f * 3.0f);

        //Relative BandWidth
        bw *= powf(100, (pars.Phrelbw[pos[n]] - 64.0f) / 64.0f);

        if(bw > 25.0f)
            bw = 25.0f;

        //try to keep same amplitude on all freqs and bw. (empirically)
        float gain = sqrt(1500.0f / (bw * freq));

        float hmagnew = 1.0f - pars.Phmag[pos[n]] / 127.0f;
        float hgain;

        switch(pars.Phmagtype) {
            case 1:
                hgain = expf(hmagnew * logf(0.01f));
                break;
            case 2:
                hgain = expf(hmagnew * logf(0.001f));
                break;
            case 3:
                hgain = expf(hmagnew * logf(0.0001f));
                break;
            case 4:
                hgain = expf(hmagnew * logf(0.00001f));
                break;
            default:
                hgain = 1.0f - hmagnew;
        }
        gain      *= hgain;
        reduceamp += hgain;

        for(int nph = 0; nph < numstages; ++nph) {
            float amp = 1.0f;
            if(nph == 0)
                amp = gain;
            initfilter(lfilter[nph + n * numstages], freq + OffsetHz, bw,
                       amp, hgain);
            if(stereo)
                initfilter(rfilter[nph + n * numstages], freq + OffsetHz, bw,
                           amp, hgain);
        }
    }

    if(reduceamp < 0.001f)
        reduceamp = 1.0f;
    volume /= reduceamp;

    oldpitchwheel = 0;
    oldbandwidth  = 64;
    if(!legato) {
        if(pars.Pfixedfreq == 0)
            initparameters(basefreq);
        else
            initparameters(basefreq / 440.0f * freq);
    }
    else {
        if(pars.Pfixedfreq == 0)
            freq = basefreq;
        else
            freq *= basefreq / 440.0f;

        if(pars.PGlobalFilterEnabled) {
            globalfiltercenterq      = pars.GlobalFilter->getq();
            GlobalFilterFreqTracking = pars.GlobalFilter->getfreqtracking(
                basefreq);
        }
    }

    oldamplitude = newamplitude;
}
Example #5
0
int main(int argc, char **argv)
{
    mesh_t *mesh;
    double double_message[5];
    double x, y, z, factor = 0, vscut = 0;
    double elapsedtime;
#ifndef NO_OUTPUT
    int32_t eindex;
    int32_t remains, batch, idx;
    mrecord_t *partTable;
#endif

    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &myID);
    MPI_Comm_size(MPI_COMM_WORLD, &theGroupSize);

    /* Read commandline arguments  */
    if (argc != 5) {
	if (myID == 0) {
	    fprintf(stderr, "usage: qmesh cvmdb physics.in numerical.in ");
	    fprintf(stderr, "meshdb\n");
	    fprintf(stderr,
		    "cvmdb: path to an etree database or a flat file.\n");
	    fprintf(stderr, "physics.in: path to physics.in.\n");
	    fprintf(stderr, "numerical.in: path to numerical.in.\n");
	    fprintf(stderr, "meshetree: path to the output mesh etree.\n");
	    fprintf(stderr, "\n");
	}
	MPI_Finalize();
	return -1;
    }

    /* Change the working directory to $LOCAL */
    /*
    localpath = getenv("LOCAL");
    if (localpath == NULL) {
        fprintf(stderr, "Thread %d: Cannot get $LOCAL value\n", myID);
        MPI_Abort(MPI_COMM_WORLD, ERROR);
        exit(1);
    }

    if (chdir(localpath) != 0) {
        fprintf(stderr, "Thread %d: Cannot chdir to %s\n", myID, localpath);
        MPI_Abort(MPI_COMM_WORLD, ERROR);
        exit(1);
    }
    */

    /* Replicate the material database among the processors */
    /*

    if ((theGroupSize - 1) / PROCPERNODE >= 1) {

        MPI_Comm replica_comm;

        if (myID % PROCPERNODE != 0) {
            MPI_Comm_split(MPI_COMM_WORLD, MPI_UNDEFINED, myID, &replica_comm);

        } else {
            int replica_id;
            off_t filesize, remains, batchsize;
            void *filebuf;
            int fd;

            MPI_Comm_split(MPI_COMM_WORLD, 0, myID, &replica_comm);
            MPI_Comm_rank(replica_comm, &replica_id);

            if (replica_id == 0) {

                struct stat statbuf;


                if (stat(argv[1], &statbuf) != 0) {
                    fprintf(stderr, "Thread 0: Cannot get stat of %s\n",
                            argv[1]);
                    MPI_Abort(MPI_COMM_WORLD, ERROR);
                    exit(1);
                }

                filesize = statbuf.st_size;
            }

            MPI_Bcast(&filesize, sizeof(off_t), MPI_CHAR, 0, replica_comm);

            if ((filebuf = malloc(FILEBUFSIZE)) == NULL) {
                fprintf(stderr, "Thread %d: run out of memory while ", myID);
                fprintf(stderr, "preparing to receive material database\n");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }

	    fd = (replica_id == 0) ?
	    open(argv[1], O_RDONLY) :
                open(argv[1], O_CREAT|O_TRUNC|O_WRONLY, S_IRUSR|S_IWUSR);

            if (fd == -1) {
                fprintf(stderr, "Thread %d: Cannot create replica database\n",
                        myID);
                perror("open");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }

            remains = filesize;
            while (remains > 0) {
                batchsize = (remains > FILEBUFSIZE) ? FILEBUFSIZE : remains;

                if (replica_id == 0) {
                    if (read(fd, filebuf, batchsize) !=  batchsize) {
                        fprintf(stderr, "Thread 0: Cannot read database\n");
                        perror("read");
                        MPI_Abort(MPI_COMM_WORLD, ERROR);
                        exit(1);
                    }
                }

                MPI_Bcast(filebuf, batchsize, MPI_CHAR, 0, replica_comm);

                if (replica_id != 0) {
                    if (write(fd, filebuf, batchsize) != batchsize) {
                        fprintf(stderr, "Thread %d: Cannot write replica ",
                                myID);
                        fprintf(stderr, "database\n");
                        MPI_Abort(MPI_COMM_WORLD, ERROR);
                        exit(1);
                    }
                }

                remains -= batchsize;
		}

            if (close(fd) != 0) {
                fprintf(stderr, "Thread %d: cannot close replica database\n",
                        myID);
                perror("close");
                MPI_Abort(MPI_COMM_WORLD, ERROR);
                exit(1);
            }
	    }

        MPI_Barrier(MPI_COMM_WORLD);

	}

    */



    /* Initialize static global varialbes */
    if (myID == 0) {
	/* Processor 0 reads the parameters */
	if (initparameters(argv[2], argv[3], &x, &y, &z) != 0) {
	    fprintf(stderr, "Thread %d: Cannot init parameters\n", myID);
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	factor = theFactor;
	vscut = theVsCut;
	double_message[0] = x;
	double_message[1] = y;
	double_message[2] = z;
	double_message[3] = factor;
	double_message[4] = vscut;

	/*
          fprintf(stderr, "&double_message[0] = %p\n", &double_message[0]);
          fprintf(stderr, "&double_message[4] = %p\n", &double_message[4]);
	  fprintf(stderr, "Thread 0: %f %f %f %f %f\n", x, y, z, factor, vscut);
        */
    }

    MPI_Bcast(double_message, 5, MPI_DOUBLE, 0, MPI_COMM_WORLD);

    x = double_message[0];
    y = double_message[1];
    z = double_message[2];
    factor = double_message[3];
    vscut  = double_message[4];

    theNorth_m = x;
    theEast_m = y;
    theDepth_m = z;

    /*
      printf("Thread %d: %f %f %f %f %f\n", myID, x, y, z, factor, vscut);
    */

    theFactor = factor;
    theVsCut = vscut;

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime = -MPI_Wtime();


    if (myID == 0) {
	fprintf(stdout, "PE = %d, Freq = %.2f\n", theGroupSize, theFreq);
	fprintf(stdout, "-----------------------------------------------\n");
    }


    /*----  Generate and partition an unstructured octree mesh ----*/
    if (myID == 0) {
	fprintf(stdout, "octor_newtree ... ");
    }

    /*
     * RICARDO: Carful with new_octree parameters (cutoff_depth)
     */

    myOctree = octor_newtree(x, y, z, sizeof(edata_t), myID, theGroupSize, MPI_COMM_WORLD, 0);
    if (myOctree == NULL) {
	fprintf(stderr, "Thread %d: fail to create octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();

    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#ifdef USECVMDB
    /* Open my copy of the material database */
    theCVMEp = etree_open(argv[1], O_RDONLY, CVMBUFSIZE, 0, 0);
    if (!theCVMEp) {
	fprintf(stderr, "Thread %d: Cannot open CVM etree database %s\n",
		myID, argv[1]);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

#else

    /* Use flat data record file and distibute the data in memories */
    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "slicing CVM database ...");
    }

    theCVMRecord = sliceCVM(argv[1]);

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime += MPI_Wtime();
    if (theCVMRecord == NULL) {
	fprintf(stderr, "Thread %d: Error obtaining the CVM records from %s\n",
		myID, argv[1]);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    };
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#endif

    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_refinetree ...");
    }
    if (octor_refinetree(myOctree, toexpand, setrec) != 0) {
	fprintf(stderr, "Thread %d: fail to refine octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

    MPI_Barrier(MPI_COMM_WORLD);
    elapsedtime += MPI_Wtime();

    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }


    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_balancetree ... ");
    }
    if (octor_balancetree(myOctree, setrec, 0) != 0) { /* no progressive meshing (ricardo) */
	fprintf(stderr, "Thread %d: fail to balance octree\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

#ifdef USECVMDB
    /* Close the material database */
    etree_close(theCVMEp);
#else
    free(theCVMRecord);

#endif /* USECVMDB */

    elapsedtime = -MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_partitiontree ...");
    }
    if (octor_partitiontree(myOctree, NULL) != 0) {
	fprintf(stderr, "Thread %d: fail to balance load\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime +=  MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

    elapsedtime = - MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "octor_extractmesh ... ");
    }
    mesh = octor_extractmesh(myOctree, NULL);
    if (mesh == NULL) {
	fprintf(stderr, "Thread %d: fail to extract mesh\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    elapsedtime += MPI_Wtime();
    if (myID == 0) {
	fprintf(stdout, "done.... %.2f seconds\n", elapsedtime);
    }

    /* We can do without the octree now */
    octor_deletetree(myOctree);


    /*---- Obtain and print the statistics of the mesh ----*/
    if (myID == 0) {
	int64_t etotal, ntotal, dntotal;
	int32_t received, procid;
	int32_t *enumTable, *nnumTable, *dnnumTable;
	int32_t rcvtrio[3];

	/* Allocate the arrays to hold the statistics */
	enumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);
	nnumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);
	dnnumTable = (int32_t *)malloc(sizeof(int32_t) * theGroupSize);

	if ((enumTable == NULL) ||
	    (nnumTable == NULL) ||
	    (dnnumTable == NULL)) {
	    fprintf(stderr, "Thread 0: out of memory\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	/* Fill in my counts */
	enumTable[0] = mesh->lenum;
	nnumTable[0] = mesh->lnnum;
	dnnumTable[0] = mesh->ldnnum;

	/* Initialize sums */
	etotal = mesh->lenum;
	ntotal = mesh->lnnum;
	dntotal = mesh->ldnnum;

	/* Fill in the rest of the tables */
	received = 0;
	while (received < theGroupSize - 1) {
	    int32_t fromwhom;
	    MPI_Status status;

	    MPI_Probe(MPI_ANY_SOURCE, STAT_MSG, MPI_COMM_WORLD, &status);

	    fromwhom = status.MPI_SOURCE;

	    MPI_Recv(rcvtrio, 3, MPI_INT, fromwhom, STAT_MSG, MPI_COMM_WORLD,
		     &status);

	    enumTable[fromwhom] = rcvtrio[0];
	    nnumTable[fromwhom] = rcvtrio[1];
	    dnnumTable[fromwhom] = rcvtrio[2];

	    etotal += rcvtrio[0];
	    ntotal += rcvtrio[1];
	    dntotal += rcvtrio[2];

	    received++;
	}

	fprintf(stdout, "Mesh statistics:\n");
	fprintf(stdout, "                 Elements     Nodes    Danglings\n");
#ifdef ALPHA_TRU64UNIX_CC
	fprintf(stdout, "Total     :   %10ld%10ld   %10ld\n\n",
		etotal, ntotal, dntotal);
	for (procid = 0; procid < theGroupSize; procid++) {
	    fprintf(stdout, "Proc %5d:   %10d%10d   %10d\n", procid,
		    enumTable[procid], nnumTable[procid], dnnumTable[procid]);
	}

#else
	fprintf(stdout, "Total      :    %10qd%10qd   %10qd\n\n",
		etotal, ntotal, dntotal);
	for (procid = 0; procid < theGroupSize; procid++) {
	    fprintf(stdout, "Proc %5d:   %10d%10d   %10d\n", procid,
		    enumTable[procid], nnumTable[procid], dnnumTable[procid]);
	}
#endif

	free(enumTable);
	free(nnumTable);
	free(dnnumTable);

    } else {
	int32_t sndtrio[3];

	sndtrio[0] = mesh->lenum;
	sndtrio[1] = mesh->lnnum;
	sndtrio[2] = mesh->ldnnum;

	MPI_Send(sndtrio, 3, MPI_INT, 0, STAT_MSG, MPI_COMM_WORLD);
    }

#ifndef NO_OUTPUT

    /*---- Join elements and nodes, and send to Thread 0 for output */

    /* Allocate a fixed size buffer space to store the join results */
    partTable = (mrecord_t *)calloc(BATCH, sizeof(mrecord_t));
    if (partTable == NULL) {
	fprintf(stderr,	 "Thread %d: out of memory\n", myID);
	MPI_Abort(MPI_COMM_WORLD, ERROR);
	exit(1);
    }

    if (myID == 0) {
	char *mEtree;
	etree_t *mep;
	int32_t procid;

	mEtree = argv[4];
	mep = etree_open(mEtree, O_CREAT|O_RDWR|O_TRUNC, 0, sizeof(mdata_t),3);
	if (mep == NULL) {
	    fprintf(stderr, "Thread 0: cannot create mesh etree\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	/* Begin an appending operation */
	if (etree_beginappend(mep, 1) != 0) {
	    fprintf(stderr, "Thread 0: cannot begin an append operation\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

	eindex = 0;
	while (eindex < mesh->lenum) {
	    remains = mesh->lenum - eindex;
	    batch = (remains < BATCH) ? remains : BATCH;

	    for (idx = 0; idx < batch; idx++) {
		mrecord_t *mrecord;
		int32_t whichnode;
		int32_t localnid0;

		mrecord = &partTable[idx];

		/* Fill the address field */
		localnid0 = mesh->elemTable[eindex].lnid[0];

		mrecord->addr.x = mesh->nodeTable[localnid0].x;
		mrecord->addr.y = mesh->nodeTable[localnid0].y;
		mrecord->addr.z = mesh->nodeTable[localnid0].z;
		mrecord->addr.level = mesh->elemTable[eindex].level;
		mrecord->addr.type = ETREE_LEAF;

		/* Find the global node ids for the vertices */
		for (whichnode = 0; whichnode < 8; whichnode++) {
		    int32_t localnid;
		    int64_t globalnid;

		    localnid = mesh->elemTable[eindex].lnid[whichnode];
		    globalnid = mesh->nodeTable[localnid].gnid;

		    mrecord->mdata.nid[whichnode] = globalnid;
		}

		memcpy(&mrecord->mdata.edgesize, mesh->elemTable[eindex].data,
		       sizeof(edata_t));

		eindex++;
	    } /* for a batch */

	    if (bulkload(mep, partTable, batch) != 0) {
		fprintf(stderr, "Thread 0: Error bulk-loading data\n");
		MPI_Abort(MPI_COMM_WORLD, ERROR);
		exit(1);
	    }
	} /* for all the elements Thread 0 has */

	/* Receive data from other processors */
	for (procid = 1; procid < theGroupSize; procid++) {
	    MPI_Status status;
	    int32_t rcvbytecount;

	    /* Signal the next processor to go ahead */
	    MPI_Send(NULL, 0, MPI_CHAR, procid, GOAHEAD_MSG, MPI_COMM_WORLD);

	    while (1) {
		MPI_Probe(procid, MESH_MSG, MPI_COMM_WORLD, &status);
		MPI_Get_count(&status, MPI_CHAR, &rcvbytecount);

		batch = rcvbytecount / sizeof(mrecord_t);
		if (batch == 0) {
		    /* Done */
		    break;
		}

		MPI_Recv(partTable, rcvbytecount, MPI_CHAR, procid,
			 MESH_MSG, MPI_COMM_WORLD, &status);

		if (bulkload(mep, partTable, batch) != 0) {
		    fprintf(stderr, "Thread 0: Cannot bulk-load data from ");
		    fprintf(stderr, "Thread %d\n", procid);
		    MPI_Abort(MPI_COMM_WORLD, ERROR);
		    exit(1);
		}
	    } /* while there is more data to be received from procid */
	} /* for all the processors */

	/* End the appending operation */
	etree_endappend(mep);

	/* Close the mep to ensure the data is on disk */
	if (etree_close(mep) != 0) {
	    fprintf(stderr, "Thread 0: Cannot close the etree database\n");
	    MPI_Abort(MPI_COMM_WORLD, ERROR);
	    exit(1);
	}

    } else {
	/* Processors other than 0 needs to send data to 0 */
	int32_t sndbytecount;
	MPI_Status status;

	/* Wait for my turn */
	MPI_Recv(NULL, 0, MPI_CHAR, 0, GOAHEAD_MSG, MPI_COMM_WORLD, &status);

	eindex = 0;
	while (eindex < mesh->lenum) {
	    remains = mesh->lenum - eindex;
	    batch = (remains < BATCH) ? remains : BATCH;

	    for (idx = 0; idx < batch; idx++) {
		mrecord_t *mrecord;
		int32_t whichnode;
		int32_t localnid0;

		mrecord = &partTable[idx];

		/* Fill the address field */
		localnid0 = mesh->elemTable[eindex].lnid[0];

		mrecord->addr.x = mesh->nodeTable[localnid0].x;
		mrecord->addr.y = mesh->nodeTable[localnid0].y;
		mrecord->addr.z = mesh->nodeTable[localnid0].z;
		mrecord->addr.level = mesh->elemTable[eindex].level;
		mrecord->addr.type = ETREE_LEAF;

		/* Find the global node ids for the vertices */
		for (whichnode = 0; whichnode < 8; whichnode++) {
		    int32_t localnid;
		    int64_t globalnid;

		    localnid = mesh->elemTable[eindex].lnid[whichnode];
		    globalnid = mesh->nodeTable[localnid].gnid;

		    mrecord->mdata.nid[whichnode] = globalnid;
		}

		memcpy(&mrecord->mdata.edgesize, mesh->elemTable[eindex].data,
		       sizeof(edata_t));

		eindex++;
	    } /* for a batch */

	    /* Send data to proc 0 */
	    sndbytecount = batch * sizeof(mrecord_t);
	    MPI_Send(partTable, sndbytecount, MPI_CHAR, 0, MESH_MSG,
		     MPI_COMM_WORLD);
	} /* While there is data left to be sent */

	/* Send an empty message to indicate the end of my transfer */
	MPI_Send(NULL, 0, MPI_CHAR, 0, MESH_MSG, MPI_COMM_WORLD);
    }

    /* Free the memory for the partial join results */
    free(partTable);

#endif

    octor_deletemesh(mesh);

    MPI_Finalize();

    return 0;
}
Example #6
0
SUBnote::SUBnote(SUBnoteParameters *parameters,
                 Controller *ctl_,
                 REALTYPE freq,
                 REALTYPE velocity,
                 int portamento_,
                 int midinote,
                 bool besilent)
{
    ready=0;

    tmpsmp=new REALTYPE[SOUND_BUFFER_SIZE];
    tmprnd=new REALTYPE[SOUND_BUFFER_SIZE];

	this->velocity=velocity;
	this->freq = freq;

    // Initialise some legato-specific vars
    Legato.msg=LM_Norm;
    Legato.fade.length=(int)(SAMPLE_RATE*0.005);// 0.005 seems ok.
    if (Legato.fade.length<1) Legato.fade.length=1;// (if something's fishy)
    Legato.fade.step=(1.0/Legato.fade.length);
    Legato.decounter=-10;
    Legato.param.freq=freq;
    Legato.param.vel=velocity;
    Legato.param.portamento=portamento_;
    Legato.param.midinote=midinote;
    Legato.silent=besilent;

    pars=parameters;
    ctl=ctl_;
    portamento=portamento_;
    NoteEnabled=ON;
    volume=pow(0.1,3.0*(1.0-pars->PVolume/96.0));//-60 dB .. 0 dB
    volume*=VelF(velocity,pars->PAmpVelocityScaleFunction);
    if (pars->PPanning!=0) panning=pars->PPanning/127.0;
    else panning=RND;
    numstages=pars->Pnumstages;
    stereo=pars->Pstereo;
    start=pars->Pstart;
    firsttick=1;
    //int pos[MAX_SUB_HARMONICS];

    if (pars->Pfixedfreq==0) basefreq=freq;
    else {
        basefreq=440.0;
        int fixedfreqET=pars->PfixedfreqET;
        if (fixedfreqET!=0) {//if the frequency varies according the keyboard note
            REALTYPE tmp=(midinote-69.0)/12.0*(pow(2.0,(fixedfreqET-1)/63.0)-1.0);
            if (fixedfreqET<=64) basefreq*=pow(2.0f,tmp);
            else basefreq*=pow(3.0f,tmp);
        };

    };
    REALTYPE detune=getdetune(pars->PDetuneType,pars->PCoarseDetune,pars->PDetune);
    basefreq*=pow(2.0,detune/1200.0);//detune
//    basefreq*=ctl->pitchwheel.relfreq;//pitch wheel

    //global filter
    GlobalFilterCenterPitch=pars->GlobalFilter->getfreq()+//center freq
                            (pars->PGlobalFilterVelocityScale/127.0*6.0)* //velocity sensing
                            (VelF(velocity,pars->PGlobalFilterVelocityScaleFunction)-1);

    GlobalFilterL=NULL;
    GlobalFilterR=NULL;
    GlobalFilterEnvelope=NULL;

    //select only harmonics that desire to compute
    numharmonics=0;
    for (int n=0;n<MAX_SUB_HARMONICS;n++) {
        if (pars->Phmag[n]==0)continue;
        if (n*basefreq>SAMPLE_RATE/2.0) break;//remove the freqs above the Nyquist freq
        pos[numharmonics++]=n;
    };
    firstnumharmonics=numharmonics;//(gf)Useful in legato mode.

    if (numharmonics==0) {
        NoteEnabled=OFF;
        return;
    };


    lfilter=new bpfilter[numstages*numharmonics];
    if (stereo!=0) rfilter=new bpfilter[numstages*numharmonics];

    //how much the amplitude is normalised (because the harmonics)
    reduceamp=0.0;

    for (int n=0;n<numharmonics;n++) {

        REALTYPE freq=basefreq*(pos[n]+1);

        //the bandwidth is not absolute(Hz); it is relative to frequency
        REALTYPE bw=pow(10,(pars->Pbandwidth-127.0)/127.0*4)*numstages;

        //Bandwidth Scale
        bw*=pow(1000/freq,(float)((pars->Pbwscale-64.0)/64.0*3.0));

        //Relative BandWidth
        bw*=pow(100,(float)((pars->Phrelbw[pos[n]]-64.0)/64.0));

        if (bw>25.0) bw=25.0;

        //try to keep same amplitude on all freqs and bw. (empirically)
        gain=sqrt(1500.0/(bw*freq));

        hmagnew=1.0-pars->Phmag[pos[n]]/127.0;
        //hgain;

        switch (pars->Phmagtype) {
        case 1:
            hgain=exp(hmagnew*log(0.01));
            break;
        case 2:
            hgain=exp(hmagnew*log(0.001));
            break;
        case 3:
            hgain=exp(hmagnew*log(0.0001));
            break;
        case 4:
            hgain=exp(hmagnew*log(0.00001));
            break;
        default:
            hgain=1.0-hmagnew;
        };
        gain*=hgain;
        reduceamp+=hgain;

        for (int nph=0;nph<numstages;nph++) {
            REALTYPE amp=1.0;
            if (nph==0) amp=gain;
            initfilter(lfilter[nph+n*numstages],freq,bw,amp,hgain);
            if (stereo!=0) initfilter(rfilter[nph+n*numstages],freq,bw,amp,hgain);
        };
    };

    if (reduceamp<0.001) reduceamp=1.0;
    volume/=reduceamp;

    oldpitchwheel=0;
    oldbandwidth=64;
    if (pars->Pfixedfreq==0) initparameters(basefreq);
    else initparameters(basefreq/440.0*freq);

    oldamplitude=newamplitude;
    ready=1;
};