当前位置: 首页>>代码示例>>C++>>正文


C++ posix_memalign函数代码示例

本文整理汇总了C++中posix_memalign函数的典型用法代码示例。如果您正苦于以下问题:C++ posix_memalign函数的具体用法?C++ posix_memalign怎么用?C++ posix_memalign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了posix_memalign函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: return

bool PlatformRPI::MyMalloc(void **memptr, size_t alignment, size_t size)
{
	return (posix_memalign(memptr, alignment, size) == 0);
}
开发者ID:Charles32,项目名称:SyncVideoPi,代码行数:4,代码来源:PlatformRPI.cpp

示例2: main

int main(int argc, char **argv)
{
	// Check arguments
	if (argc < 2) {
		// Default operation
	} else if (argc == 2) {
		// Check arg
		unsigned long arg = strtol(argv[1], NULL, 0);
		if (arg == 0)
			usage();
		else
			loopCnt = arg;
	}
	// Error
	else {
		usage();
	}


	printf("\nHtBcm Test\n\n");

	int nau = HtBcmPrepare(&BcmReportNonce, &BcmFreeTask);

	printf("  Running with %d Units\n", nau);
	printf("  Looping %d Times\n", loopCnt);

	// Alloc g_pBcmTask
	g_pBcmTask = (CHtBcmTask **)calloc(loopCnt * nau, sizeof(CHtBcmTask));

	// For each loop
	for (int j = 0; j < loopCnt; j += 1) {
		printf("\nLoop %d\n", j + 1);
		g_bReportNonce = false;
		g_BcmFreeTaskCnt = 0;

		// Create Task for each Unit
		for (int i = 0; i < nau; i++) {
			int cnt = i + j * nau + 1;
			int total = loopCnt * nau;
			printf("HtBcm Hash Instance %d of %d created\n", cnt, total);

			block_header header;

			BcmHex2bin(header.version, "01000000");
			BcmHex2bin(header.prev_block, "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000");
			BcmHex2bin(header.merkle_root, "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b");
			BcmHex2bin(header.timestamp, "c7f5d74d");
			BcmHex2bin(header.bits, "f2b9441a");
			BcmHex2bin(header.nonce, "42a14695");

			// put header in big endian format
			BcmEndianFlip((uint8_t *)&header, (uint8_t *)&header, 80);

			//RegenHash(&header);

			posix_memalign((void **)&g_pBcmTask[cnt - 1], 64, sizeof(CHtBcmTask) * 1);

			BcmCalcMidState(g_pBcmTask[cnt - 1]->m_midState, (uint8_t *)&header);

			memcpy(g_pBcmTask[cnt - 1]->m_data, ((uint8_t *)&header) + 64, 12);

			uint32_t target[8];
			uint32_t bits = BcmByteSwap32(*(uint32_t *)header.bits);
			BcmInitTarget(target, bits);

			memcpy(g_pBcmTask[cnt - 1]->m_target, target + 5, 12);

			g_pBcmTask[cnt - 1]->m_initNonce = init_nonce;
			g_pBcmTask[cnt - 1]->m_lastNonce = last_nonce;

			HtBcmAddNewTask(g_pBcmTask[cnt - 1]);
		}

		// Force ScanHash call until all units have returned
		while (!g_bReportNonce || (g_BcmFreeTaskCnt < nau))
			HtBcmScanHash((void *)1);

		for (int i = 0; i < nau; i++) {
			int cnt = i + j * nau + 1;
			free(g_pBcmTask[cnt - 1]);
		}
	}

	// All loops complete, finish up
	printf("%s\n", g_bError ? "FAILED" : "PASSED");

	free(g_pBcmTask);

	HtBcmShutdown();
}
开发者ID:CarlEbeling,项目名称:OpenHT,代码行数:90,代码来源:Main.cpp

示例3: main

int main(int argc, char *argv[])
{
	int op, ret;

	struct iovec s_iov[IOV_CNT], r_iov[IOV_CNT];
	char *s_buf, *r_buf;
	int align_size;
	int pairs, print_rate;
	int window_varied;
	int c, j;
	int curr_size;
	enum send_recv_type_e type;

	ctpm_Init(&argc, &argv);
	ctpm_Rank(&myid);
	ctpm_Job_size(&numprocs);

	/* default values */
	pairs            = numprocs / 2;
	window_size      = DEFAULT_WINDOW;
	window_varied    = 0;
	print_rate       = 1;

	hints = fi_allocinfo();
	if (!hints)
		return -1;

	while ((op = getopt(argc, argv, "hp:w:vr:" CT_STD_OPTS)) != -1) {
		switch (op) {
		default:
			ct_parse_std_opts(op, optarg, hints);
			break;
		case 'p':
			pairs = atoi(optarg);
			if (pairs > (numprocs / 2)) {
				print_usage();
				return EXIT_FAILURE;
			}
			break;
		case 'w':
			window_size = atoi(optarg);
			break;
		case 'v':
			window_varied = 1;
			break;
		case 'r':
			print_rate = atoi(optarg);
			if (0 != print_rate && 1 != print_rate) {
				print_usage();
				return EXIT_FAILURE;
			}
			break;
		case '?':
		case 'h':
			print_usage();
			return EXIT_FAILURE;
		}
	}

	hints->ep_attr->type	= FI_EP_RDM;
	hints->caps		= FI_MSG | FI_DIRECTED_RECV;
	hints->mode		= FI_CONTEXT | FI_LOCAL_MR;

	if (numprocs < 2) {
		if (!myid) {
			fprintf(stderr, "This test requires at least two processes\n");
		}
		ctpm_Finalize();
		return -1;
	}

	/* Fabric initialization */
	ret = init_fabric();
	if (ret) {
		fprintf(stderr, "Problem in fabric initialization\n");
		return ret;
	}

	ret = init_av();
	if (ret) {
		fprintf(stderr, "Problem in AV initialization\n");
		return ret;
	}

	/* Data initialization */
	align_size = getpagesize();
	assert(align_size <= MAX_ALIGNMENT);

	/* Allocate page aligned buffers */
	for (c = 0; c < IOV_CNT; c++) {
		assert(!posix_memalign(&s_iov[c].iov_base, align_size, MAX_MSG_SIZE));
		assert(!posix_memalign(&r_iov[c].iov_base, align_size, MAX_MSG_SIZE));
	}

	assert(!posix_memalign((void **)&s_buf, align_size, MAX_MSG_SIZE * IOV_CNT));
	assert(!posix_memalign((void **)&r_buf, align_size, MAX_MSG_SIZE * IOV_CNT));

	for (type = 0; type < FIN; type++) {
		if (!myid) {
			fprintf(stdout, HEADER);
//.........这里部分代码省略.........
开发者ID:e-harvey,项目名称:cray-tests,代码行数:101,代码来源:rdm_mbw_mr.c

示例4: malloc

void *av_malloc(size_t size)
{
    void *ptr = NULL;
#if CONFIG_MEMALIGN_HACK
    long diff;
#endif

    /* let's disallow possibly ambiguous cases */
    if (size > (max_alloc_size - 32))
        return NULL;

#if CONFIG_MEMALIGN_HACK
    ptr = malloc(size + ALIGN);
    if (!ptr)
        return ptr;
    diff              = ((~(long)ptr)&(ALIGN - 1)) + 1;
    ptr               = (char *)ptr + diff;
    ((char *)ptr)[-1] = diff;
#elif HAVE_POSIX_MEMALIGN
    if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation
    if (posix_memalign(&ptr, ALIGN, size))
        ptr = NULL;
#elif HAVE_ALIGNED_MALLOC
    ptr = _aligned_malloc(size, ALIGN);
#elif HAVE_MEMALIGN
#ifndef __DJGPP__
    ptr = memalign(ALIGN, size);
#else
    ptr = memalign(size, ALIGN);
#endif
    /* Why 64?
     * Indeed, we should align it:
     *   on  4 for 386
     *   on 16 for 486
     *   on 32 for 586, PPro - K6-III
     *   on 64 for K7 (maybe for P3 too).
     * Because L1 and L2 caches are aligned on those values.
     * But I don't want to code such logic here!
     */
    /* Why 32?
     * For AVX ASM. SSE / NEON needs only 16.
     * Why not larger? Because I did not see a difference in benchmarks ...
     */
    /* benchmarks with P3
     * memalign(64) + 1          3071, 3051, 3032
     * memalign(64) + 2          3051, 3032, 3041
     * memalign(64) + 4          2911, 2896, 2915
     * memalign(64) + 8          2545, 2554, 2550
     * memalign(64) + 16         2543, 2572, 2563
     * memalign(64) + 32         2546, 2545, 2571
     * memalign(64) + 64         2570, 2533, 2558
     *
     * BTW, malloc seems to do 8-byte alignment by default here.
     */
#else
    ptr = malloc(size);
#ifdef USE_MEM_STATS
    printf("malloc(%ld) -> %p\n", size, ptr);
    if (ptr) {
        mem_cur += malloc_usable_size(ptr);
        if (mem_cur > mem_max) {
            mem_max = mem_cur;
            printf("mem_max=%d\n", mem_max);
        }
    }
#endif
#endif
    if(!ptr && !size) {
        size = 1;
        ptr= av_malloc(1);
    }
#if CONFIG_MEMORY_POISONING
    if (ptr)
        memset(ptr, FF_MEMORY_POISON, size);
#endif
    return ptr;
}
开发者ID:gtalusan,项目名称:libbpg,代码行数:77,代码来源:mem.c

示例5: getenv

void *VSIMalloc( size_t nSize )

{
    if (nMaxPeakAllocSize < 0)
    {
        char* pszMaxPeakAllocSize = getenv("CPL_MAX_PEAK_ALLOC_SIZE");
        nMaxPeakAllocSize = (pszMaxPeakAllocSize) ? atoi(pszMaxPeakAllocSize) : 0;
        char* pszMaxCumulAllocSize = getenv("CPL_MAX_CUMUL_ALLOC_SIZE");
        nMaxCumulAllocSize = (pszMaxCumulAllocSize) ? atoi(pszMaxCumulAllocSize) : 0;
    }
    if (nMaxPeakAllocSize > 0 && (GIntBig)nSize > nMaxPeakAllocSize)
        return NULL;
#ifdef DEBUG_VSIMALLOC_STATS
    if (nMaxCumulAllocSize > 0 && (GIntBig)nCurrentTotalAllocs + (GIntBig)nSize > nMaxCumulAllocSize)
        return NULL;
#endif  // DEBUG_VSIMALLOC_STATS

#ifdef DEBUG_VSIMALLOC_MPROTECT
    char* ptr = NULL;
    size_t nPageSize = getpagesize();
    posix_memalign((void**)&ptr, nPageSize, (3 * sizeof(void*) + nSize + nPageSize - 1) & ~(nPageSize - 1));
#else
    char* ptr = (char*) malloc(3 * sizeof(void*) + nSize);
#endif  // DEBUG_VSIMALLOC_MPROTECT
    if (ptr == NULL)
        return NULL;
    ptr[0] = 'V';
    ptr[1] = 'S';
    ptr[2] = 'I';
    ptr[3] = 'M';
    memcpy(ptr + sizeof(void*), &nSize, sizeof(void*));
    ptr[2 * sizeof(void*) + nSize + 0] = 'E';
    ptr[2 * sizeof(void*) + nSize + 1] = 'V';
    ptr[2 * sizeof(void*) + nSize + 2] = 'S';
    ptr[2 * sizeof(void*) + nSize + 3] = 'I';
#if defined(DEBUG_VSIMALLOC_STATS) || defined(DEBUG_VSIMALLOC_VERBOSE)
    {
        CPLMutexHolderD(&hMemStatMutex);
#ifdef DEBUG_VSIMALLOC_VERBOSE
        if( nSize > THRESHOLD_PRINT )
        {
            fprintf(stderr, "Thread[%p] VSIMalloc(%d) = %p"
#ifdef DEBUG_VSIMALLOC_STATS
                         ", current_cumul = " CPL_FRMT_GUIB
#ifdef DEBUG_BLOCK_CACHE_USE
                         ", block_cache_used = " CPL_FRMT_GIB
#endif
                         ", mal+cal-free = %d"
#endif
                         "\n",
                (void*)CPLGetPID(), (int)nSize, ptr + 2 * sizeof(void*)
#ifdef DEBUG_VSIMALLOC_STATS
                , (GUIntBig)(nCurrentTotalAllocs + nSize),
#ifdef DEBUG_BLOCK_CACHE_USE
                , GDALGetCacheUsed64()
#endif
                ,(int)(nVSIMallocs + nVSICallocs - nVSIFrees)
#endif
                );
        }
#endif  // DEBUG_VSIMALLOC_VERBOSE
#ifdef DEBUG_VSIMALLOC_STATS
        nVSIMallocs ++;
        if (nMaxTotalAllocs == 0)
            atexit(VSIShowMemStats);
        nCurrentTotalAllocs += nSize;
        if (nCurrentTotalAllocs > nMaxTotalAllocs)
            nMaxTotalAllocs = nCurrentTotalAllocs;
#endif  // DEBUG_VSIMALLOC_STATS
    }
开发者ID:Wedjaa,项目名称:node-gdal,代码行数:70,代码来源:cpl_vsisimple.cpp

示例6: main

int main(int argc, char *argv[])
{
        int i, j, rtest, m, k, nerrs, r;
        void *buf;
        u8 *temp_buffs[TEST_SOURCES], *buffs[TEST_SOURCES];
        u8 a[MMAX * KMAX], b[MMAX * KMAX], c[MMAX * KMAX], d[MMAX * KMAX];
        u8 g_tbls[KMAX * TEST_SOURCES * 32], src_in_err[TEST_SOURCES];
        u8 src_err_list[TEST_SOURCES], *recov[TEST_SOURCES];
        struct perf start, stop;

        // Pick test parameters
        m = 14;
        k = 10;
        nerrs = 4;
        const u8 err_list[] = {2, 4, 5, 7};

        printf("erasure_code_base_perf: %dx%d %d\n", m, TEST_LEN(m), nerrs);

        if (m > MMAX || k > KMAX || nerrs > (m - k)){
                printf(" Input test parameter error\n");
                return -1;
        }

        memcpy(src_err_list, err_list, nerrs);
        memset(src_in_err, 0, TEST_SOURCES);
        for (i = 0; i < nerrs; i++)
                src_in_err[src_err_list[i]] = 1;

        // Allocate the arrays
        for (i = 0; i < m; i++) {
                if (posix_memalign(&buf, 64, TEST_LEN(m))) {
                        printf("alloc error: Fail\n");
                        return -1;
                }
                buffs[i] = buf;
        }

        for (i = 0; i < (m - k); i++) {
                if (posix_memalign(&buf, 64, TEST_LEN(m))) {
                        printf("alloc error: Fail\n");
                        return -1;
                }
                temp_buffs[i] = buf;
        }

        // Make random data
        for (i = 0; i < k; i++)
                for (j = 0; j < TEST_LEN(m); j++)
                        buffs[i][j] = rand();

        gf_gen_rs_matrix(a, m, k);
        ec_init_tables(k, m - k, &a[k * k], g_tbls);
        ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);

        // Start encode test
        perf_start(&start);
        for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
                // Make parity vects
                ec_init_tables(k, m - k, &a[k * k], g_tbls);
                ec_encode_data_base(TEST_LEN(m), k, m - k, g_tbls, buffs, &buffs[k]);
        }
        perf_stop(&stop);
        printf("erasure_code_base_encode" TEST_TYPE_STR ": ");
        perf_print(stop, start, (long long)(TEST_LEN(m)) * (m) * rtest);

        // Start decode test
        perf_start(&start);
        for (rtest = 0; rtest < TEST_LOOPS(m); rtest++) {
                // Construct b by removing error rows
                for (i = 0, r = 0; i < k; i++, r++) {
                        while (src_in_err[r])
                                r++;
                        recov[i] = buffs[r];
                        for (j = 0; j < k; j++)
                                b[k * i + j] = a[k * r + j];
                }

                if (gf_invert_matrix(b, d, k) < 0) {
                        printf("BAD MATRIX\n");
                        return -1;
                }

                for (i = 0; i < nerrs; i++)
                        for (j = 0; j < k; j++)
                                c[k * i + j] = d[k * src_err_list[i] + j];

                // Recover data
                ec_init_tables(k, nerrs, c, g_tbls);
                ec_encode_data_base(TEST_LEN(m), k, nerrs, g_tbls, recov, temp_buffs);
        }
        perf_stop(&stop);

        for (i = 0; i < nerrs; i++) {
                if (0 != memcmp(temp_buffs[i], buffs[src_err_list[i]], TEST_LEN(m))) {
                        printf("Fail error recovery (%d, %d, %d) - ", m, k, nerrs);
                        return -1;
                }
        }

        printf("erasure_code_base_decode" TEST_TYPE_STR ": ");
//.........这里部分代码省略.........
开发者ID:mattf,项目名称:minio,代码行数:101,代码来源:erasure-code-base-perf.c

示例7: main

int main(int argc, char *argv[]) {
	if(argc < 3) {
		printf("Usage: $0 dfe_ip cpu_ip\n");
		return 1;
	}

	struct in_addr dfe_ip;
	inet_aton(argv[1], &dfe_ip);
	struct in_addr cpu_ip;
	inet_aton(argv[2], &cpu_ip);
	struct in_addr netmask;
	inet_aton("255.255.255.0", &netmask);
	const int port = 5007;

	max_file_t *maxfile = Tracker_init();
	max_engine_t * engine = max_load(maxfile, "*");


	max_config_set_bool(MAX_CONFIG_PRINTF_TO_STDOUT, true);

	max_actions_t *actions = max_actions_init(maxfile, NULL);
	char regName[32];
	for (int i=0; i < 1024; i++) {
		sprintf(regName, "filter_%d", i);
		if (i == 150) {
			max_set_uint64t(actions, "filteringKernel", regName, 0xCC /* a value to match... */);
		} else {
			max_set_uint64t(actions, "filteringKernel", regName, 0x4D1B /* or any value you want */);
		}
	}
	max_run(engine, actions);
	max_actions_free(actions);


	void *buffer;
	size_t bufferSize = 4096 * 512;
	posix_memalign(&buffer, 4096, bufferSize);

	max_framed_stream_t *toCpu = max_framed_stream_setup(engine, "toCPU", buffer, bufferSize, -1);

	/*
	 * This executable both creates a normal Linux UDP socket as well as a DFE UDP Socket.
	 * We then exchange data between the two.
	 */

	// DFE Socket
	max_ip_config(engine, MAX_NET_CONNECTION_QSFP_TOP_10G_PORT1, &dfe_ip, &netmask);
	max_udp_socket_t *dfe_socket = max_udp_create_socket(engine, "udpTopPort1");
	max_udp_bind(dfe_socket, port);
	max_udp_connect(dfe_socket, &cpu_ip, port);


	// Linux Socket
	int cpu_socket = create_cpu_udp_socket(&cpu_ip, &dfe_ip, port);

	printf("Sending test frame...\n");
	sendTestFrame(cpu_socket);

	printf("Waiting for kernel response...\n"); fflush(stdout);

	void *f;
	size_t fsz;
	size_t numMessageRx = 0;
	uint8_t received_data[512];
	while (numMessageRx < NUM_MESSAGES_EXPECTED) {
		if (max_framed_stream_read(toCpu, 1, &f, &fsz) == 1) {
			printf("CPU: Got output frame - size %zd - NumMsg = %zd!\n", fsz, numMessageRx); // Frame size would be rounded up to the next 8 bytes.

			memcpy(received_data, f, fsz);
			numMessageRx++;
			max_framed_stream_discard(toCpu, 1);
		} else 	usleep(10);
	}

	max_udp_close(dfe_socket);
	max_unload(engine);
	max_file_free(maxfile);

	printf("Done.\n"); fflush(stdout);
	return 0;
}
开发者ID:huabinruan,项目名称:NetworkingCodeExamples,代码行数:81,代码来源:tracker.c

示例8: init_problem_data

static void init_problem_data(void)
{
	unsigned i,j;

#ifdef STARPU_USE_CUDA
	if (pin) {
		starpu_data_malloc_pinned_if_possible((void **)&A, zdim*ydim*sizeof(float));
		starpu_data_malloc_pinned_if_possible((void **)&B, xdim*zdim*sizeof(float));
		starpu_data_malloc_pinned_if_possible((void **)&C, xdim*ydim*sizeof(float));
	} else
#endif
	{
#ifdef STARPU_HAVE_POSIX_MEMALIGN
		posix_memalign((void **)&A, 4096, zdim*ydim*sizeof(float));
		posix_memalign((void **)&B, 4096, xdim*zdim*sizeof(float));
		posix_memalign((void **)&C, 4096, xdim*ydim*sizeof(float));
#else
		A = malloc(zdim*ydim*sizeof(float));
		B = malloc(xdim*zdim*sizeof(float));
		C = malloc(xdim*ydim*sizeof(float));
#endif
	}

	/* fill the A and B matrices */
	if (norandom) {
		for (j=0; j < ydim; j++) {
			for (i=0; i < zdim; i++) {
				A[j+i*ydim] = (float)(i);
			}
		}
	
		for (j=0; j < zdim; j++) {
			for (i=0; i < xdim; i++) {
				B[j+i*zdim] = (float)(j);
			}
		}
	} 
	else {
#ifdef NORANDOM
		srand(2008);
		STARPU_ABORT();
#endif
		for (j=0; j < ydim; j++) {
			for (i=0; i < zdim; i++) {
				A[j+i*ydim] = (float)(starpu_drand48());
			}
		}
	
		for (j=0; j < zdim; j++) {
			for (i=0; i < xdim; i++) {
				B[j+i*zdim] = (float)(starpu_drand48());
			}
		}
	}

	for (j=0; j < ydim; j++) {
		for (i=0; i < xdim; i++) {
			C[j+i*ydim] = (float)(0);
		}
	}

	display_memory_consumption();
}
开发者ID:alucas,项目名称:StarPU,代码行数:63,代码来源:dw_mult.c

示例9: main

int main (int argc, char* argv[])
{
    const int width = 40;
    const int height = 40;

    float* input, *output1, *output2;
    float* input_sc, *output1_sc, *output2_sc;
   
   
    if(posix_memalign((void **) &input,     64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }
    if(posix_memalign((void **) &output1, 64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }
    if(posix_memalign((void **) &output2,  64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }
    if(posix_memalign((void **) &input_sc,     64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }
    if(posix_memalign((void **) &output1_sc, 64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }
    if(posix_memalign((void **) &output2_sc,  64, 4 * width*height * sizeof(float)) != 0)
    {
        exit(1);
    }

    int i;
    for (i=0; i<(width*height*4); i++)
    {
        input[i] = (i*0.9f)/(i+1);
        input_sc[i] = (i*0.9f)/(i+1);
    }

    blackscholes(width, height, input, output1, output2);
    blackscholes_sc(width, height, input_sc, output1_sc, output2_sc);
    
 
    for (i=0; i<(width*height*4); i++)
    {
        if(fabsf(input_sc[i] - input[i]) > 0.01f)
        {
            printf("ERROR\n");
            exit(1);
        }
        if(fabsf(output1_sc[i] - output1[i]) > 0.01f)
        {
            printf("ERROR\n");
            exit(1);
        }
        if(fabsf(output2_sc[i] - output2[i]) > 0.01f)
        {
            printf("ERROR\n");
            exit(1);
        }
    }

    return 0;
}
开发者ID:bsc-pm,项目名称:mcxx,代码行数:66,代码来源:success_simd_04_serial_blackscholes.c

示例10: pmem_memcpy_init

/*
 * pmem_memcpy_init -- benchmark initialization
 *
 * Parses command line arguments, allocates persistent memory, and maps it.
 */
static int
pmem_memcpy_init(struct benchmark *bench, struct benchmark_args *args)
{
	assert(bench != NULL);
	assert(args != NULL);
	int ret = 0;

	struct pmem_bench *pmb = malloc(sizeof (struct pmem_bench));
	assert(pmb != NULL);

	pmb->pargs = args->opts;
	assert(pmb->pargs != NULL);

	pmb->pargs->chunk_size = args->dsize;

	enum operation_type op_type;
	/*
	 * Assign file and buffer size depending on the operation type
	 * (READ from PMEM or WRITE to PMEM)
	 */
	if (assign_size(pmb, args, &op_type) != 0) {
		ret = -1;
		goto err_free_pmb;
	}

	if ((errno = posix_memalign(
		(void **) &pmb->buf, FLUSH_ALIGN, pmb->bsize)) != 0) {
		perror("posix_memalign");
		ret = -1;
		goto err_free_pmb;
	}

	pmb->n_rand_offsets = args->n_ops_per_thread * args->n_threads;
	pmb->rand_offsets = malloc(pmb->n_rand_offsets *
			sizeof (*pmb->rand_offsets));

	if (pmb->rand_offsets == NULL) {
		perror("malloc");
		ret = -1;
		goto err_free_pmb;
	}

	for (size_t i = 0; i < pmb->n_rand_offsets; ++i)
		pmb->rand_offsets[i] = rand() % args->n_ops_per_thread;

	/* create a pmem file and memory map it */
	if ((pmb->pmem_addr = pmem_map_file(args->fname, pmb->fsize,
				PMEM_FILE_CREATE|PMEM_FILE_EXCL,
				args->fmode, NULL, NULL)) == NULL) {
		perror(args->fname);
		ret = -1;
		goto err_free_buf;
	}

	if (op_type == OP_TYPE_READ) {
		pmb->src_addr = pmb->pmem_addr;
		pmb->dest_addr = pmb->buf;
	} else {
		pmb->src_addr = pmb->buf;
		pmb->dest_addr = pmb->pmem_addr;
	}

	/* set proper func_src() and func_dest() depending on benchmark args */
	if ((pmb->func_src = assign_mode_func(pmb->pargs->src_mode)) == NULL) {
		fprintf(stderr, "wrong src_mode parameter -- '%s'",
						pmb->pargs->src_mode);
		ret = -1;
		goto err_unmap;
	}

	if ((pmb->func_dest = assign_mode_func(pmb->pargs->dest_mode))
								== NULL) {
		fprintf(stderr, "wrong dest_mode parameter -- '%s'",
						pmb->pargs->dest_mode);
		ret = -1;
		goto err_unmap;
	}

	if (pmb->pargs->memcpy) {
		pmb->func_op = pmb->pargs->persist ?
					libc_memcpy_persist : libc_memcpy;
	} else {
		pmb->func_op = pmb->pargs->persist ?
			libpmem_memcpy_persist : libpmem_memcpy_nodrain;
	}

	pmembench_set_priv(bench, pmb);

	return 0;

err_unmap:
	pmem_unmap(pmb->pmem_addr, pmb->fsize);
err_free_buf:
	free(pmb->buf);
err_free_pmb:
//.........这里部分代码省略.........
开发者ID:dardevelin,项目名称:nvml,代码行数:101,代码来源:pmem_memcpy.c

示例11: thread

static void thread(int id)
{
	struct timeval start, stop, diff;
	int fd, i, ret;
	size_t n;
	void *buf;
	int flags = O_CREAT | O_RDWR | O_LARGEFILE;
	char filename[32];

	ret = posix_memalign(&buf, PAGE_SIZE, chunk_size);
	if (ret < 0) {
		fprintf(stderr,
			"ERROR: task %d couldn't allocate %lu bytes (%s)\n",
                       id, chunk_size, strerror(errno));
		exit(1);
	}
	memset(buf, 0xaa, chunk_size);

	snprintf(filename, sizeof(filename), "%s-%d-iobw.tmp", mygroup, id);
	if (directio)
		flags |= O_DIRECT;
	fd = open(filename, flags, 0600);
	if (fd < 0) {
		fprintf(stderr, "ERROR: task %d couldn't open %s (%s)\n",
			id, filename, strerror(errno));
		free(buf);
		exit(1);
	}

	/* Write */
	lseek(fd, 0, SEEK_SET);
	n = 0;
	gettimeofday(&start, NULL);
	while (n < data_size) {
		i = write(fd, buf, chunk_size);
		if (i < 0) {
			fprintf(stderr, "ERROR: task %d writing to %s (%s)\n",
				id, filename, strerror(errno));
			ret = 1;
			goto out;
		}
		n += i;
	}
        gettimeofday(&stop, NULL);
        timersub(&stop, &start, &diff);
	print_results(id + 1, OP_WRITE, data_size, &diff);

	/* Read */
	lseek(fd, 0, SEEK_SET);
	n = 0;
	gettimeofday(&start, NULL);
	while (n < data_size) {
		i = read(fd, buf, chunk_size);
		if (i < 0) {
			fprintf(stderr, "ERROR: task %d reading to %s (%s)\n",
				id, filename, strerror(errno));
			ret = 1;
			goto out;
		}
		n += i;
	}
        gettimeofday(&stop, NULL);
        timersub(&stop, &start, &diff);
	print_results(id + 1, OP_READ, data_size, &diff);
out:
	close(fd);
	unlink(filename);
	free(buf);
	exit(ret);
}
开发者ID:ystk,项目名称:debian-ltp,代码行数:70,代码来源:iobw.c

示例12: posix_memalign

static void *aligned_malloc(void **base, int size)
{
	return posix_memalign(base, 8192, size) ? NULL : *base;
}
开发者ID:mbroz,项目名称:dm_int_tools,代码行数:4,代码来源:main.c

示例13: main


//.........这里部分代码省略.........
        if (fd < 0)
            err(2, "failed to open \"%s\"", path);

        if (get_device_size(fd, &st)) {
            if (!S_ISCHR(st.st_mode))
                err(2, "block get size ioctl failed");
            st.st_size = offset + temp_wsize;
            fstype = "character";
            device = "device";
        } else {
            device_size = st.st_size;
            fstype = "block";
            device = "device ";
        }

        if (!cached && write_test && fdatasync(fd)) {
            warnx("fdatasync not supported by \"%s\", "
                  "enable cached requests", path);
            cached = 1;
        }
    } else {
        errx(2, "unsupported destination: \"%s\"", path);
    }

    if (wsize > st.st_size || offset > st.st_size - wsize)
        errx(2, "target is too small for this");

    if (!wsize)
        wsize = st.st_size - offset;

    if (size > wsize)
        errx(2, "request size is too big for this target");

    ret = posix_memalign(&buf, 0x1000, size);
    if (ret)
        errx(2, "buffer allocation failed");

    random_memory(buf, size);

    if (S_ISDIR(st.st_mode)) {
        fd = create_temp(path, "ioping.tmp");
        if (fd < 0)
            err(2, "failed to create temporary file at \"%s\"", path);
        if (keep_file) {
            if (fstat(fd, &st))
                err(2, "fstat at \"%s\" failed", path);
            if (st.st_size >= offset + wsize)
#ifndef __MINGW32__
                if (st.st_blocks >= (st.st_size + 511) / 512)
#endif
                    goto skip_preparation;
        }
        for (woffset = 0 ; woffset < wsize ; woffset += ret_size) {
            ret_size = size;
            if (woffset + ret_size > wsize)
                ret_size = wsize - woffset;
            if (woffset)
                random_memory(buf, ret_size);
            ret_size = pwrite(fd, buf, ret_size, offset + woffset);
            if (ret_size <= 0)
                err(2, "preparation write failed");
        }
skip_preparation:
        if (fsync(fd))
            err(2, "fsync failed");
    } else if (S_ISREG(st.st_mode)) {
开发者ID:yksuh,项目名称:ioping,代码行数:67,代码来源:ioping.c

示例14: instantiateFIR

void instantiateFIR(FIR* pFIR, const uint uiSampleRate)
{
	printf("FIR: instantiating FIR with %d samples / s\n", uiSampleRate);
	//check which base frequency to use
	float** ppfDataSource = NULL;
	uint nSourceRate = 0;
	uint* pnSourceBufferLengths = NULL;

	switch(uiSampleRate)
	{
	case 44100:
	case 22050:
	case 88200:
		ppfDataSource = g_aafFIRs44k1;
		nSourceRate = 44100;
		pnSourceBufferLengths = g_anSamples44k1;
		break;
	default:
	//case 48000:
	//case 96000:
	//case 192000:
		ppfDataSource = g_aafFIRs48k;
		nSourceRate = 48000;
		pnSourceBufferLengths = g_anSamples48k;
		break;
	}

	double fRateScaler = (float)nSourceRate / (double)uiSampleRate;

	printf("FIR: chosen rate %d, scaler %f\n", nSourceRate, fRateScaler);

	//reserve buffer
	uint uiModel = 0;
	for(; uiModel < NUM_MODELS; uiModel++)
	{
		uint nSourceSamples = pnSourceBufferLengths[uiModel];

		uint n8Tuples = (uint)(fRateScaler * (float)nSourceSamples - 1.0f) / 8 + 1;

		pFIR->m_anHistory8Tuples[uiModel] = n8Tuples;

		uint nDestSamples = n8Tuples * 8;


#ifdef _MSC_VER
		pFIR->m_apfHistory[uiModel] = (v8f_t*) _aligned_malloc(n8Tuples * sizeof(v8f_t), 16);
#else
		posix_memalign((void**)&(pFIR->m_apfHistory[uiModel]), sizeof(v8f_t), n8Tuples * sizeof(v8f_t));
#endif

#ifdef _MSC_VER
		pFIR->m_apfFIR[uiModel] = (v8f_t*) _aligned_malloc(nDestSamples * sizeof(v8f_t), 16);
#else
		posix_memalign((void**)&(pFIR->m_apfFIR[uiModel]), sizeof(v8f_t), nDestSamples * sizeof(v8f_t));
#endif

		//fill fir coefficients
		//the fir is reversed here, so multiplication with history data can be carried out sequentially
		uint uiPermutation = 0;
		for(; uiPermutation < 8; uiPermutation++)
		{
			uint uiFIRSample = 0;
			while (uiFIRSample < nDestSamples)
			{
				float afCoeffs[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
				const uint uiStartSample = uiFIRSample;
				for (; uiFIRSample < uiStartSample + 8 && uiFIRSample < nDestSamples; uiFIRSample++)
				{
					uint uiSourcePosUnscaled = (uiPermutation - uiFIRSample + nDestSamples) % nDestSamples;
					uint uiSourceBufferPos = (uint)((double)uiSourcePosUnscaled * fRateScaler);

					if(uiSourceBufferPos < nSourceSamples)
						afCoeffs[uiFIRSample & 0x7] = ppfDataSource[uiModel][uiSourceBufferPos];
				}

				const uint uiDestIndex = uiPermutation * n8Tuples + (uiStartSample >> 3);
				pFIR->m_apfFIR [uiModel][uiDestIndex] = v8f_create(afCoeffs);
			}
		}
	}
	memset(pFIR->m_auiBufferPos, 0, NUM_MODELS * sizeof(uint));
}
开发者ID:kaktus3000,项目名称:HighGain,代码行数:82,代码来源:FIR.c

示例15: crypto_scrypt

/**
 * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
 * Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
 * p, buflen) and write the result into buf.  The parameters r, p, and buflen
 * must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32.  The parameter N
 * must be a power of 2 greater than 1.
 *
 * Return 0 on success; or -1 on error.
 */
int
crypto_scrypt(const uint8_t * passwd, size_t passwdlen,
    const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p,
    uint8_t * buf, size_t buflen)
{
	void * B0, * V0, * XY0;
	uint8_t * B;
	uint32_t * V;
	uint32_t * XY;
	uint32_t i;

	/* Sanity-check parameters. */
#if SIZE_MAX > UINT32_MAX
	if (buflen > (((uint64_t)(1) << 32) - 1) * 32) {
		errno = EFBIG;
		goto err0;
	}
#endif
	if ((uint64_t)(r) * (uint64_t)(p) >= (1 << 30)) {
		errno = EFBIG;
		goto err0;
	}
	if (((N & (N - 1)) != 0) || (N == 0)) {
		errno = EINVAL;
		goto err0;
	}
	if ((r > SIZE_MAX / 128 / p) ||
#if SIZE_MAX / 256 <= UINT32_MAX
	    (r > SIZE_MAX / 256) ||
#endif
	    (N > SIZE_MAX / 128 / r)) {
		errno = ENOMEM;
		goto err0;
	}

	/* Allocate memory. */
#ifdef _WIN32
#undef HAVE_POSIX_MEMALIGN
#endif

#ifdef HAVE_POSIX_MEMALIGN
	if ((errno = posix_memalign(&B0, 64, 128 * r * p)) != 0)
		goto err0;
	B = (uint8_t *)(B0);
	if ((errno = posix_memalign(&XY0, 64, 256 * r + 64)) != 0)
		goto err1;
	XY = (uint32_t *)(XY0);
#ifndef MAP_ANON
	if ((errno = posix_memalign(&V0, 64, 128 * r * N)) != 0)
		goto err2;
	V = (uint32_t *)(V0);
#endif
#else
	if ((B0 = malloc(128 * r * p + 63)) == NULL)
		goto err0;
	B = (uint8_t *)(((uintptr_t)(B0) + 63) & ~ (uintptr_t)(63));
	if ((XY0 = malloc(256 * r + 64 + 63)) == NULL)
		goto err1;
	XY = (uint32_t *)(((uintptr_t)(XY0) + 63) & ~ (uintptr_t)(63));
#ifndef MAP_ANON
	if ((V0 = malloc(128 * r * N + 63)) == NULL)
		goto err2;
	V = (uint32_t *)(((uintptr_t)(V0) + 63) & ~ (uintptr_t)(63));
#endif
#endif
#ifdef MAP_ANON
	if ((V0 = mmap(NULL, 128 * r * N, PROT_READ | PROT_WRITE,
#ifdef MAP_NOCORE
	    MAP_ANON | MAP_PRIVATE | MAP_NOCORE,
#else
	    MAP_ANON | MAP_PRIVATE,
#endif
	    -1, 0)) == MAP_FAILED)
		goto err2;
	V = (uint32_t *)(V0);
#endif

	/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
	PBKDF2_scrypt_SHA256(passwd, passwdlen, salt, saltlen, 1, B, p * 128 * r);

	/* 2: for i = 0 to p - 1 do */
	for (i = 0; i < p; i++) {
		/* 3: B_i <-- MF(B_i, N) */
		smix(&B[i * 128 * r], r, N, V, XY);
	}

	/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
	PBKDF2_scrypt_SHA256(passwd, passwdlen, B, p * 128 * r, 1, buf, buflen);

	/* Free memory. */
#ifdef MAP_ANON
//.........这里部分代码省略.........
开发者ID:brooklynpacket,项目名称:py-scrypt,代码行数:101,代码来源:crypto_scrypt-nosse.c


注:本文中的posix_memalign函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。