Ejemplo n.º 1
0
Archivo: smt.c Proyecto: wtabib/15-740
int main() {

    int j = 0, k = 0;
    struct timespec start_t, end_t;
    struct timespec start_j, end_j;
    arr = (int *) calloc(NUM_ELEM*NUM_THREADS, sizeof(int));

    for (j = 1; j < NUM_THREADS; j++) {
        t = j;
        
        clock_gettime(CLOCK_REALTIME, &start_t);
        double running_sum = 0;
        for (k = 0; k < 100; k++) {
            running_sum += wrapper_func();
        }
        clock_gettime(CLOCK_REALTIME, &end_t);

        printf("%d, %g\n", j, running_sum / 100.0);
    }
    return 0;
}
Ejemplo n.º 2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    int nLabels, nNodes, nChains, a, n, Eoffset, Eoff;
    const void *U, *E;
    void *en = NULL;
    const mwSize *dims;
    int32_t *L;
    mxClassID classid;
    
    /* Check number of arguments */
    if (nrhs != 2)
        mexErrMsgTxt("Unexpected number of input arguments.");
    if (nlhs < 1 || nlhs > 2)
        mexErrMsgTxt("Unexpected number of output arguments.");
    
    /* Check input types are valid */
    classid = mxGetClassID(prhs[0]);
    if (mxGetClassID(prhs[1]) != classid)
        mexErrMsgTxt("E must be the same type as U.");
    n = mxGetNumberOfDimensions(prhs[0]);
    if (n > 3)
        mexErrMsgTxt("U has unexpected dimensions");
    dims = mxGetDimensions(prhs[0]);
    nLabels = dims[0];
    nNodes = dims[1];
    if (nNodes*nLabels < 1)
        mexErrMsgTxt("U cannot be empty.");
    if (n == 3) {
        nChains = dims[2];
    } else {
        nChains = 1;
    }
    n = mxGetNumberOfDimensions(prhs[1]);
    if (n > 4)
        mexErrMsgTxt("E has unexpected dimensions");
    dims = mxGetDimensions(prhs[1]);
    if (dims[0] != nLabels || dims[1] != nLabels)
        mexErrMsgTxt("E has unexpected dimensions");
    if (n > 2) {
        if (dims[2] != nNodes-1)
            mexErrMsgTxt("E has unexpected dimensions");
        if (n == 4) {
            if (dims[3] != nChains)
                mexErrMsgTxt("E has unexpected dimensions");
        } else {
            if (1 != nChains)
                mexErrMsgTxt("E has unexpected dimensions");
        }
        Eoffset = 0;
        Eoff = nLabels*nLabels*(nNodes-1);
    } else {
        Eoffset = nLabels*nLabels;
        Eoff = 0;
    }
    
    /* Get array pointers */
    U = (const void *)mxGetData(prhs[0]);
    E = (const void *)mxGetData(prhs[1]);
    
    /* Create the output matrices */
    plhs[0] = mxCreateUninitNumericMatrix(nNodes, nChains, mxINT32_CLASS, mxREAL);
    L = (int32_t *)mxGetData(plhs[0]);
    if (nlhs > 1) {
        plhs[1] = mxCreateUninitNumericMatrix(1, nChains, classid, mxREAL);
        en = (void *)mxGetData(plhs[1]);
    }
    
    /* Call the wrapper function according to type */
    switch (classid) {
        case mxDOUBLE_CLASS:
			wrapper_func((const double *)U, (const double *)E, L, nLabels, nNodes, Eoffset, (double *)en, nChains, Eoff);
			break;
		case mxSINGLE_CLASS:
            wrapper_func((const float *)U, (const float *)E, L, nLabels, nNodes, Eoffset, (float *)en, nChains, Eoff);
            break;
		case mxUINT32_CLASS:
            wrapper_func((const uint32_t *)U, (const uint32_t *)E, L, nLabels, nNodes, Eoffset, (uint32_t *)en, nChains, Eoff);
            break;
        default:
			mexErrMsgTxt("U and E are of an unsupported type");
			break;            
    }
}
Ejemplo n.º 3
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	// Check number of arguments
	if (nrhs < 3 || nrhs > 5)
		mexErrMsgTxt("Unexpected number of input arguments.");
	if (nlhs < 1 || nlhs > 2)
		mexErrMsgTxt("Unexpected number of output arguments.");

	// Check argument types are valid
	mxClassID in_class = mxGetClassID(prhs[1]);
	if (mxGetClassID(prhs[2]) != in_class)
		mexErrMsgTxt("X and Y must be arrays of the same type");
	for (int i = 0; i < nrhs; ++i) {
        if (mxIsComplex(prhs[i]))
			mexErrMsgTxt("Inputs cannot be complex.");
	}

	// Get and check array dimensions
	int num_points = static_cast<int>(mxGetNumberOfElements(prhs[1]));
	if (num_points != static_cast<int>(mxGetNumberOfElements(prhs[2])))
		mexErrMsgTxt("X and Y must have the same dimensions");
	int ndims = static_cast<int>(mxGetNumberOfDimensions(prhs[0]));
	std::vector<size_t> out_dims(ndims+2);
    out_dims[0] = 2;
	out_dims[1] = mxGetM(prhs[1]);
	out_dims[2] = mxGetN(prhs[1]);
	const mwSize *dims = mxGetDimensions(prhs[0]);
	out_dims[3] = 1;
	int nchannels = 1;
	for (int i = 2; i < ndims; ++i) {
		out_dims[i+1] = dims[i];
		nchannels *= static_cast<int>(dims[i]);
	}
	
	// Get the out of bounds value (oobv) and set the output class to the same class as the oobv.
	double oobv;
	mxClassID out_class;
	if (nrhs > 4) {
		// Get the value for oobv
		if (mxGetNumberOfElements(prhs[4]) != 1)
			mexErrMsgTxt("oobv must be a scalar.");
		oobv = mxGetScalar(prhs[4]);
		out_class = mxGetClassID(prhs[4]);
	} else {
		// Use the default value for oobv
		oobv = mxGetNaN();
		out_class = in_class;
	}
	
	// Create the output arrays
	plhs[0] = mxCreateUninitNumericArray(ndims, &out_dims[1], out_class, mxREAL);
	void *B = mxGetData(plhs[0]);
    void *G = NULL;
    if (nlhs > 1) {
        plhs[1] = mxCreateUninitNumericArray(ndims+1, &out_dims[0], out_class, mxREAL);
        G = mxGetData(plhs[1]);
    }

	// Get the interpolation method
    char buffer[10] = {'l'};
    int k = 0;
    if (nrhs > 3) {
        // Read in the method string
        if (mxGetString(prhs[3], buffer, sizeof(buffer)))
            mexErrMsgTxt("Unrecognised interpolation method");
        // Remove '*' from the start
        k += (buffer[k] == '*');
        // Remove 'bi' from the start
        k += 2 * ((buffer[k] == 'b') & (buffer[k+1] == 'i'));
    }
    
    // Get pointer to the input image
    const void *A = mxGetData(prhs[0]);
    
	// Call the first wrapper function according to the input image type
    const int width = static_cast<int>(dims[1]);
    const int height = static_cast<int>(dims[0]);
	switch (mxGetClassID(prhs[0])) {
		case mxDOUBLE_CLASS:
			wrapper_func(B, G, (const double *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxSINGLE_CLASS:
			wrapper_func(B, G, (const float *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxINT8_CLASS:
			wrapper_func(B, G, (const int8_t *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxUINT8_CLASS:
			wrapper_func(B, G, (const uint8_t *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxINT16_CLASS:
			wrapper_func(B, G, (const int16_t *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxUINT16_CLASS:
			wrapper_func(B, G, (const uint16_t *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		case mxLOGICAL_CLASS:
			wrapper_func(B, G, (const mxLogical *)A, prhs, num_points, width, height, nchannels, oobv, buffer[k], out_class, in_class);
			break;
		default:
			mexErrMsgTxt("A is of an unsupported type");
			break;
	}
	return;
}