Example #1
0
int main()
{
	boost::shared_ptr<const MyStruct> q = boost::make_shared<const MyStruct>(100);
	put(q);
	
	
	std::function<void (int)> fn = [](int x) {std::cout << "x = " << x << std::endl;};
	mmm(12345, fn);
	
	int *p = nullptr;
	foo(p);
	
	const int* p2 = nullptr;
	foo(p2);
	
	
	int n = 100;
	foo(n);
	
	int& n1 = n;
	foo(n1);
	const int& n2 = n1;
	foo(n2);
	
	
	
	
	
	int a = 10;
	const int b = 20;
	
	funcA(a);
	funcA(b);
	
	funcB(a);
	funcB(b);
	
	func0(a);
	//func0(b);
	
	func1(a);
	func1(b);
	
	
	
	std::cout << "\n------------- mmmm2 -------------\n";
	int	x = 100;
	mmmm2(x);
	
	int *px = &x;
	mmmm2(px);
	
	const int* px2 = &x;
	mmmm2(px2);
	
	
	
	return 0;
}
TEST(TypeConvert, CustomConverter) {
    
    // ??: why? 
    //EXPECT_EQ(10, ConvertToInt());

    ConvertToInt cit;
    EXPECT_EQ(10, cit());

    //---------------------------  ---------------------------
    CanBeAB ca;
    CanBeAB cb;
    bool sameA1 = std::is_same<decltype(ca()), A>::value;
    bool sameA2 = std::is_same<decltype(ca.operator A()), A>::value;
    EXPECT_TRUE(sameA1);
    EXPECT_TRUE(sameA2);

    bool sameB1 = std::is_same<decltype(cb()), A>::value;
    bool sameB2 = std::is_same<decltype(cb.operator B), A>::value;
    EXPECT_TRUE(sameB1);
    EXPECT_FALSE(sameB2);

    void funcA(A a);
    void funcB(B b);

    funcA(ca);
    //funcB(cb);  // error: cannot convert cb to B. (explicit operator B()).
   
    A a1(ca);
    A a2 = ca;

    B b1(cb);
    //B b2 = cb;     // error: cannot convert cb to B. (explicit operator B()). 
    B b3 = static_cast<B>(cb);
}
Example #3
0
int main() {
  
  float tmp=0;
  tmp=funcA(-1);
  tmp=0;  
  
  return 0; 
  /* Return 0 only */
}
Example #4
0
int main(int argc, char** argv) {
  FILE* f;
  if (argc < 2)
    return 1;
  f = fopen(argv[1], "wt");
  fprintf(f, "#define VALUE %d\n", funcA());
  fclose(f);
  return 0;
}
main() {

	#pragma omp parallel sections
	{
		#pragma omp section
			(void) funcA();
		#pragma omp section
			(void) funcB();
	}
}
Example #6
0
int main() {
   int a;
   a = 10;
   funcA(a);

   while(1) {
       sleep(5);
   }
   return 0;
}
Example #7
0
int main(int argc, char const *argv[])
{
	bin(funcA(2));

	putchar('\n');

	bin(funcB(4,4));

	putchar('\n');

	return 0;
}
Example #8
0
int main()
{

#pragma omp parallel num_threads(4)
{
	#pragma omp sections
	{
		#pragma omp section
			(void) funcA();

		#pragma omp section
			(void) funcB();
	} /* -- End of sections block -- */
} /* -- End of parallel region -- */
		
}
Example #9
0
File: ex46.c Project: Kun-Qu/petsc
/* 
   FormFunctionLocal - Evaluates nonlinear function, F(x).
*/
PetscErrorCode FormFunctionLocal(DMDALocalInfo *info,PetscScalar **x,PetscScalar **f,AppCtx *user)
{
  DM             coordDA;
  Vec            coordinates;
  DMDACoor2d     **coords;
  PetscScalar    u, ux, uy, uxx, uyy;
  PetscReal      D, K, hx, hy, hxdhy, hydhx;
  PetscInt       i,j;
  PetscErrorCode ierr;

  PetscFunctionBegin;

  D      = user->D;
  K      = user->K;
  hx     = 1.0/(PetscReal)(info->mx-1);
  hy     = 1.0/(PetscReal)(info->my-1);
  hxdhy  = hx/hy; 
  hydhx  = hy/hx;
  /*
     Compute function over the locally owned part of the grid
  */
  ierr = DMDAGetCoordinateDA(info->da, &coordDA);CHKERRQ(ierr);
  ierr = DMDAGetCoordinates(info->da, &coordinates);CHKERRQ(ierr);
  ierr = DMDAVecGetArray(coordDA, coordinates, &coords);CHKERRQ(ierr);
  for (j=info->ys; j<info->ys+info->ym; j++) {
    for (i=info->xs; i<info->xs+info->xm; i++) {
      if (i == 0 || j == 0 || i == info->mx-1 || j == info->my-1) {
        f[j][i] = x[j][i];
      } else {
        u       = x[j][i];
        ux      = (x[j][i+1] - x[j][i])/hx;
        uy      = (x[j+1][i] - x[j][i])/hy;
        uxx     = (2.0*u - x[j][i-1] - x[j][i+1])*hydhx;
        uyy     = (2.0*u - x[j-1][i] - x[j+1][i])*hxdhy;
        f[j][i] = D*(uxx + uyy) - (K*funcA(x[j][i], user)*sqrt(ux*ux + uy*uy) + funcU(&coords[j][i]))*hx*hy;
        if (PetscIsInfOrNanScalar(f[j][i])) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FP, "Invalid residual: %g", PetscRealPart(f[j][i]));
      }
    }
  }
  ierr = DMDAVecRestoreArray(coordDA, coordinates, &coords);CHKERRQ(ierr);
  ierr = PetscLogFlops(11*info->ym*info->xm);CHKERRQ(ierr);
  PetscFunctionReturn(0); 
} 
Example #10
0
_Bool main() {
	//Declare variables
	int num;

	printf("The game is afoot.\n");
	printf("The little dog laughed, to see such sport\n");
	printf("And the dish ran away with the spoon\n");
	printf("Enter 1, 2, or 3, anything else will end program\n");
	scanf("%d", &num);
	if (num == 1) {
		return funcA();
	}
	else if (num == 2) {
		return funcB();
	}
	else if (num == 3) {
		return funcC();
	}
	else {
		printf("The game is no longer afoot.\n");
	}
}
Example #11
0
int main(void) {
  /* A function wrapper to a member variable of a class */
  CAnyData<int> dataA{2016};
  std::function<int(CAnyData<int>&)> funcA = &CAnyData<int>::m_value;
  std::cout << funcA(dataA) << std::endl;

  /* A function wrappter to member function without parameter passing */
  CAnyData<float> dataB{2016.1};
  std::function<void(CAnyData<float>&)> funcB = &CAnyData<float>::print;
  funcB(dataB);

  /* A function wrappter to member function with passing a parameter */
  std::function<void(CAnyData<float>&, float)> funcC =
      &CAnyData<float>::printAfterAdd;
  funcC(dataB, 0.1);

  /* A function wrappter to member function generated by std::bind */
  std::function<void(float)> funcD =
      std::bind(&CAnyData<float>::printAfterAdd, &dataB, std::placeholders::_1);
  funcD(0.2);

  return 0;
}
int main()
{

	int itr;
	int nCount;		/* 문제의 테스트 케이스 */

	scanf("%d", &nCount);	/* 테스트 케이스 입력 */

	for(itr=0; itr<nCount; itr++)
	{

		printf("#testcase%d\n",itr+1);

		max_a = 0;
		max_b = 0;
		min_a = 0;
		min_b = 0;

		int a, b;

		scanf("%d %d", &a, &b);
		funcA(a);
		funcB(b);

		printf("%d %d\n", min_a + min_b, max_a + max_b);
		
		/*

		알고리즘이 들어가는 부분

		*/

	}

	return 0;	/* 반드시 return 0으로 해주셔야합니다. */ 

}
Example #13
0
File: ex46.c Project: Kun-Qu/petsc
/*
   FormJacobianLocal - Evaluates Jacobian matrix.
*/
PetscErrorCode FormJacobianLocal(DMDALocalInfo *info,PetscScalar **x,Mat jac,AppCtx *user)
{
  MatStencil     col[5], row;
  PetscScalar    D, K, A, v[5], hx, hy, hxdhy, hydhx, ux, uy;
  PetscReal      normGradZ;
  PetscInt       i, j,k;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  D      = user->D;
  K      = user->K;
  hx     = 1.0/(PetscReal)(info->mx-1);
  hy     = 1.0/(PetscReal)(info->my-1);
  hxdhy  = hx/hy; 
  hydhx  = hy/hx;

  /* 
     Compute entries for the locally owned part of the Jacobian.
      - Currently, all PETSc parallel matrix formats are partitioned by
        contiguous chunks of rows across the processors. 
      - Each processor needs to insert only elements that it owns
        locally (but any non-local elements will be sent to the
        appropriate processor during matrix assembly). 
      - Here, we set all entries for a particular row at once.
      - We can set matrix entries either using either
        MatSetValuesLocal() or MatSetValues(), as discussed above.
  */
  for (j=info->ys; j<info->ys+info->ym; j++) {
    for (i=info->xs; i<info->xs+info->xm; i++) {
      row.j = j; row.i = i;
      if (i == 0 || j == 0 || i == info->mx-1 || j == info->my-1) {
        /* boundary points */
        v[0] = 1.0;
        ierr = MatSetValuesStencil(jac,1,&row,1,&row,v,INSERT_VALUES);CHKERRQ(ierr);
      } else {
        /* interior grid points */
        ux        = (x[j][i+1] - x[j][i])/hx;
        uy        = (x[j+1][i] - x[j][i])/hy;
        normGradZ = PetscRealPart(sqrt(ux*ux + uy*uy));
        //PetscPrintf(PETSC_COMM_SELF, "i: %d j: %d normGradZ: %g\n", i, j, normGradZ);
        if (normGradZ < 1.0e-8) {
          normGradZ = 1.0e-8;
        }
        A         = funcA(x[j][i], user);

        v[0] = -D*hxdhy;                                                                          col[0].j = j - 1; col[0].i = i;
        v[1] = -D*hydhx;                                                                          col[1].j = j;     col[1].i = i-1;
        v[2] = D*2.0*(hydhx + hxdhy) + K*(funcADer(x[j][i], user)*normGradZ - A/normGradZ)*hx*hy; col[2].j = row.j; col[2].i = row.i;
        v[3] = -D*hydhx + K*A*hx*hy/(2.0*normGradZ);                                              col[3].j = j;     col[3].i = i+1;
        v[4] = -D*hxdhy + K*A*hx*hy/(2.0*normGradZ);                                              col[4].j = j + 1; col[4].i = i;
        for(k = 0; k < 5; ++k) {
          if (PetscIsInfOrNanScalar(v[k])) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_FP, "Invalid residual: %g", PetscRealPart(v[k]));
        }
        ierr = MatSetValuesStencil(jac,1,&row,5,col,v,INSERT_VALUES);CHKERRQ(ierr);
      }
    }
  }

  /* 
     Assemble matrix, using the 2-step process:
       MatAssemblyBegin(), MatAssemblyEnd().
  */
  ierr = MatAssemblyBegin(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  ierr = MatAssemblyEnd(jac,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
  /*
     Tell the matrix we will never add a new nonzero location to the
     matrix. If we do, it will generate an error.
  */
  ierr = MatSetOption(jac,MAT_NEW_NONZERO_LOCATION_ERR,PETSC_TRUE);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
Example #14
0
void f10()
{
    int a = 200;
    printf("%d\n",funcA(a));
}
Example #15
0
File: e063.c Project: githubix/c
int main() {
    funcA();
    
    return 0;
}
Example #16
0
int funcB() {
  return funcA();
}