int main(int argc, char *argv[]) {
	int i,j,k;
	if (argc<2) {
		fprintf(stderr, "Usage: dijkstra <filename>\n");
		fprintf(stderr, "Only supports matrix size is #define'd.\n");
	}
	//Open the adjacency matrix file
	FILE *fp;
	fp = fopen (argv[1],"r");
	/*Step 1: geting the working vertexs and assigning values*/
  	for (i=0;i<NUM_NODES;i++) {
    		for (j=0;j<NUM_NODES;j++) {
     			fscanf(fp,"%d",&k);
			AdjMatrix[i][j]= k;
    		}
  	}
	fclose(fp);
	chStart=0,chEnd=1999; //15 for small input; 1999 for large input
	if (chStart == chEnd) {
		printf("Shortest path is 0 in cost. Just stay where you are.\n");
		
	}else{
		startBarrier(&myBarrier);	/* Start barrier 	*/
		startThreads();			/* Start pthreads */	
	}
	printResult();
//}
	exit(0);
}
Example #2
0
int main(int argc, char *argv[]){
	clock_t start, stop;
	double ct, cmin = DBL_MAX, cmax = 0;
	int i, j;
	int iterations;
	long n;
	if (argc<2) {
    		fprintf(stderr,"Usage: bitcnts <iterations>\n");
    		exit(-1);
	}
  	iterations=atoi(argv[1]);
  	puts("Bit counter algorithm benchmark\n");
	FUNCARGS* funcArgs = (FUNCARGS*)malloc(sizeof(FUNCARGS));
	//funcArgs->randSeed = rand();
	funcArgs->randSeed = 112500;
	funcArgs->iterations = iterations;
	startBarrier(&myBarrier);
    	startThreads(4,funcArgs);
	free(funcArgs);
	/*
	FUNCARGS* funcArgs = (FUNCARGS*)malloc(sizeof(FUNCARGS));
  	for (i = n = 0; i < FUNCS; i++) {
    		start = clock();
		funcArgs->funcI = i;
		//funcArgs->randSeed = rand();
		funcArgs->randSeed = 112500;
		funcArgs->iterations = iterations;
		startBarrier(&myBarrier);
    		startThreads(3,funcArgs);
		for(j=n=0;j<PROCESSORS;j++){
			n+=ns[j];
			ns[j] = 0;
		}
    		stop = clock();
    		ct = (stop - start) / (double)CLOCKS_PER_SEC;
    		if (ct < cmin) {
	 		cmin = ct;
	 		cminix = i;
    		}
    		if (ct > cmax) {
	 		cmax = ct;
	 		cmaxix = i;
    		}   
    		printf("%-38s> Time: %7.3f sec.; Bits: %ld\n", text[i], ct, n);
  	}
	free(funcArgs);
	*/
	printf("\nBest  > %s\n", text[cminix]);
  	printf("Worst > %s\n", text[cmaxix]);
  	return 0;
}
void testNormalImpl(
    const std::function<void(paddle::CustomStackTrace<std::string>&,
                             size_t,
                             size_t,
                             paddle::ThreadBarrier&,
                             paddle::ThreadBarrier&)>& callback) {
  paddle::CustomStackTrace<std::string> tracer;
  paddle::ThreadBarrier doneBarrier(FLAGS_test_thread_num + 1);
  paddle::ThreadBarrier startBarrier(FLAGS_test_thread_num + 1);
  constexpr size_t countDown = 10;
  constexpr size_t layerSize = 1000;
  std::vector<std::unique_ptr<std::thread>> threads;
  threads.reserve(FLAGS_test_thread_num);

  for (int32_t i = 0; i < FLAGS_test_thread_num; ++i) {
    threads.emplace_back(new std::thread([&tracer,
                                          &countDown,
                                          &layerSize,
                                          &startBarrier,
                                          &doneBarrier,
                                          &callback] {
      callback(tracer, countDown, layerSize, startBarrier, doneBarrier);
    }));
  }
  size_t cntDown = countDown;
  while (cntDown-- > 0) {
    startBarrier.wait();
    sleep(1);
    doneBarrier.wait();
    ASSERT_TRUE(tracer.empty());
  }

  for (auto& thread : threads) {
    thread->join();
  }
}
/*****************************************************************************
 *@ingroup cryptoThreads
 *
 * @description
 *      This function sets up an IKE-RSA thread
 ******************************************************************************/
void ikeRsaPerformance(single_thread_test_data_t* testSetup)
{
    asym_test_params_t ikeRsaSetup;
    asym_test_params_t* setup = (asym_test_params_t*)testSetup->setupPtr;
    Cpa16U numInstances = 0;
    CpaInstanceHandle *cyInstances = NULL;
    CpaStatus status = CPA_STATUS_FAIL;
    /* This barrier is to halt this thread when run in user space context, the
     * startThreads function releases this barrier, in kernel space it does
     * nothing, but kernel space threads do not start until we call startThreads
     * anyway*/
    startBarrier();
    /*give our thread a unique memory location to store performance stats*/
    ikeRsaSetup.performanceStats = testSetup->performanceStats;
    /*get the instance handles so that we can start our thread on the selected
    * instance*/
    status = cpaCyGetNumInstances(&numInstances);
    if( CPA_STATUS_SUCCESS != status  || numInstances == 0)
    {
        PRINT_ERR("cpaCyGetNumInstances error, status:%d, numInstanaces:%d\n",
                status, numInstances);
        ikeRsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        sampleCodeThreadExit();
    }
    cyInstances = qaeMemAlloc(sizeof(CpaInstanceHandle)*numInstances);
    if(cyInstances == NULL)
    {
        PRINT_ERR("Error allocating memory for instance handles\n");
        ikeRsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        sampleCodeThreadExit();
    }
    if(cpaCyGetInstances(numInstances, cyInstances) != CPA_STATUS_SUCCESS)
    {
        PRINT_ERR("Failed to get instances\n");
        ikeRsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        qaeMemFree((void**)&cyInstances);
        sampleCodeThreadExit();
    }
    if(testSetup->logicalQaInstance > numInstances)
    {
        PRINT_ERR("%u is Invalid Logical QA Instance, max is: %u\n",
                testSetup->logicalQaInstance, numInstances);
        ikeRsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        qaeMemFree((void**)&cyInstances);
        sampleCodeThreadExit();
    }
    /* give our thread a logical crypto instance to use
     * use % to wrap around the max number of instances*/
    ikeRsaSetup.cyInstanceHandle = cyInstances[testSetup->logicalQaInstance];
    ikeRsaSetup.modulusSizeInBytes = setup->modulusSizeInBytes;
    ikeRsaSetup.exponentSizeInBytes = setup->exponentSizeInBytes;
    ikeRsaSetup.numBuffers = setup->numBuffers;
    ikeRsaSetup.numLoops = setup->numLoops;
    ikeRsaSetup.rsaKeyRepType = setup->rsaKeyRepType;
    ikeRsaSetup.syncMode = ASYNC;
    /*launch function that does all the work*/
    status = ikeRsaPerform(&ikeRsaSetup);
    if(CPA_STATUS_SUCCESS != status)
    {
        PRINT("ikeRsa Thread FAILED with status: %d\n", status);
        ikeRsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
    }
    else
    {
        /*set the print function that can be used to print stats at the end of
         * the test*/
        testSetup->statsPrintFunc=(stats_print_func_t)ikeRsaPrintStats;
    }
    qaeMemFree((void**)&cyInstances);
    sampleCodeThreadExit();

}
/**
 *****************************************************************************
 * @ingroup dsaPerformance
 *      dsaPerformance
 *
 * @description
 *     This function is called by the framework to execute the dsaPerform
 *     thread
 *
 *****************************************************************************/
void dsaPerformance(single_thread_test_data_t* testSetup)
{
    dsa_test_params_t dsaSetup;
    Cpa16U numInstances = 0;
    CpaInstanceHandle *cyInstances = NULL;
    CpaStatus status = CPA_STATUS_FAIL;
    dsa_test_params_t* params = (dsa_test_params_t*)testSetup->setupPtr;
    CpaInstanceInfo2 instanceInfo = {0};

    /*this barrier is to halt this thread when run in user space context, the
     * startThreads function releases this barrier, in kernel space it does
     * nothing, but kernel space threads do not start until we call startThreads
     * anyway */
    startBarrier();
    /*give our thread a unique memory location to store performance stats */
    dsaSetup.threadID = testSetup->threadID;
    dsaSetup.performanceStats = testSetup->performanceStats;
    dsaSetup.hashAlg= params->hashAlg;
    dsaSetup.pLenInBytes= params->pLenInBytes;
    dsaSetup.qLenInBytes= params->qLenInBytes;
    dsaSetup.numBuffers = params->numBuffers;
    dsaSetup.numLoops = params->numLoops;
    dsaSetup.syncMode = params->syncMode;
    /*get the instance handles so that we can start our thread on the selected
     * instance */
    status = cpaCyGetNumInstances(&numInstances);
    if(CPA_STATUS_SUCCESS != status || numInstances == 0)
    {
        PRINT_ERR("Could not get any instances\n");
        PRINT_ERR("DSA Thread FAILED\n");
        dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        sampleCodeThreadExit();
    }
    cyInstances = qaeMemAlloc(sizeof(CpaInstanceHandle) * numInstances);
    if(NULL == cyInstances)
    {
        PRINT_ERR("Could not allocate memory for logical instances\n");
        dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        sampleCodeThreadExit();
    }
    cpaCyGetInstances(numInstances, cyInstances);
    /* give our thread a logical crypto instance to use
     * use % to wrap around the max number of instances */
    dsaSetup.cyInstanceHandle =
        cyInstances[(testSetup->logicalQaInstance)%numInstances];

    status = cpaCyInstanceGetInfo2(dsaSetup.cyInstanceHandle,
                &instanceInfo);
    if(CPA_STATUS_SUCCESS != status)
    {
        PRINT_ERR("%s::%d cpaCyInstanceGetInfo2 failed", __func__,__LINE__);
        qaeMemFree((void**)&cyInstances);
        dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
        sampleCodeThreadExit();
    }
    if(instanceInfo.physInstId.packageId > packageIdCount_g)
    {
        packageIdCount_g = instanceInfo.physInstId.packageId;
    }

    /*launch function that does all the work */
    status = dsaPerform(&dsaSetup);
    if(CPA_STATUS_SUCCESS != status)
    {
        PRINT("DSA Thread %u FAILED\n", testSetup->threadID);
        dsaSetup.performanceStats->threadReturnStatus = CPA_STATUS_FAIL;
    }
    else
    {
		/*set the print function that can be used to print stats at the end of
         * the test */
        testSetup->statsPrintFunc=(stats_print_func_t)dsaPrintStats;
    }
    qaeMemFree((void**)&cyInstances);
    sampleCodeThreadExit();
}