示例#1
0
文件: Ex4.c 项目: marrusian/C
int main(void)
{
   double darr[] = {-23.35, 0.332, 65.3, 9.66, 44,3, -14.3};
 
   printf("The largest value stored in darr[] is: %g\n", find_dmax(darr, BEYOND(darr)));   

   return 0;
}
示例#2
0
文件: Ex13.c 项目: marrusian/C
int main(void)
{
   double arr[ROWS][COLS];

   for(int i=0; i<ROWS; ++i){
      printf("\nEnter the %d%s set of five floating-point numbers:\n",
              i+1, i? (i==1? "nd" : "rd") : "st");    
      for(int j=0; j<COLS; ++j)
         arr[i][j] = get_double();
   }

   for(int i=0; i<ROWS; ++i)
      printf("%d%s average: %.2f\n", i+1, i? (i==1? "nd" : "rd") : "st",
             mean_dvalue(arr[i],BEYOND(arr[i])));

   printf("The average value of all sets: %.2f\n", mean_dvalue((double*)arr, (double*)BEYOND(arr)));
   printf("The largest value of all sets: %.2f\n", find_dmax((double*)arr, (double*)BEYOND(arr)));

   return 0;
}
示例#3
0
int main ( int argc, char ** argv ) 
{
    /* General variables */
    int hwidth, rank, size, err;

    int i, j, k,it;
    char *winner_name;
    int impl_classes[NB_OF_SIZES][NB_OF_IMPL];
    int winners[NB_OF_SIZES][2];
    double t_start, dmax, distance[NB_OF_SIZES], relation[NB_OF_SIZES], elapsed_time[14], g_elapsed_time[NB_OF_SIZES][14];

    /* Definition of the 2-D vector */
    int dims[3], neighbors[6];
    double ***data, ****data2;
    ADCL_Vmap vmap; 
    ADCL_Vector vec;

    /* Variables for the process topology information */
    int cdims[]={0,0,0};
    int periods[]={0,0,0};
    MPI_Comm cart_comm;
    ADCL_Topology topo;
    ADCL_Request request;

    /* Initiate the MPI environment */
    MPI_Init ( &argc, &argv );
    MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
    MPI_Comm_size ( MPI_COMM_WORLD, &size );

    /* Describe the neighborhood relations */
    MPI_Dims_create ( size, 3, cdims );
    MPI_Cart_create ( MPI_COMM_WORLD, 3, cdims, periods, 0, &cart_comm);
    MPI_Cart_shift ( cart_comm, 0, 1, &(neighbors[0]), &(neighbors[1]));
    MPI_Cart_shift ( cart_comm, 1, 1, &(neighbors[2]), &(neighbors[3]));
    MPI_Cart_shift ( cart_comm, 2, 1, &(neighbors[4]), &(neighbors[5]));


    /* Initiate the ADCL library and register a topology object with ADCL */
    ADCL_Init ();
    ADCL_Topology_create ( cart_comm, &topo );

    /**********************************************************************/
    /* hwidth=1, nc=0 */
    hwidth=1;
    for (i=0; i<NB_OF_SIZES; i++) {
        dims[0] = ProblemSizes[i][0] + 2*hwidth;
        dims[1] = ProblemSizes[i][1] + 2*hwidth;
        dims[2] = ProblemSizes[i][2] + 2*hwidth;

        if(rank == 0) {
            printf("Explored Problem Size %dX%dX%d \n", ProblemSizes[i][0],ProblemSizes[i][1], ProblemSizes[i][2] );
        }
        err = ADCL_Vmap_halo_allocate ( hwidth, &vmap );
        if ( ADCL_SUCCESS != err) goto exit;
        err = ADCL_Vector_allocate_generic ( 3,  dims, 0, vmap, MPI_DOUBLE, &data, &vec );
        if ( ADCL_SUCCESS != err) goto exit;
        ADCL_Request_create ( vec, topo, ADCL_FNCTSET_NEIGHBORHOOD, &request );

        /* Evaluate implementation 1 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_aao_IsendIrecv( request );
        }
        elapsed_time[0] = MPI_Wtime()-t_start;

        /* Evaluate implementation 2 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_aao_SendIrecv( request );
        }
        elapsed_time[1] = MPI_Wtime()-t_start;

        /* Evaluate implementation 3 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_aao_IsendIrecv_pack( request );
        }
        elapsed_time[2] = MPI_Wtime()-t_start;

        /* Evaluate implementation 4 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_aao_SendIrecv_pack( request );
        }
        elapsed_time[3] = MPI_Wtime()-t_start;

        /* Evaluate implementation 5 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_IsendIrecv( request );
        }
        elapsed_time[4] = MPI_Wtime()-t_start;

        /* Evaluate implementation 6 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_IsendIrecv_pack( request );
        }
        elapsed_time[5] = MPI_Wtime()-t_start;

       /* Evaluate implementation 7 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_SendIrecv( request );
        }
        elapsed_time[6] = MPI_Wtime()-t_start;

        /* Evaluate implementation 8 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_SendIrecv_pack( request );
        }
        elapsed_time[7] = MPI_Wtime()-t_start;

        /* Evaluate implementation 9 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_Sendrecv( request );
        }
        elapsed_time[8] = MPI_Wtime()-t_start;

        /* Evaluate implementation 10 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_Send_Recv( request );
        }
        elapsed_time[9] = MPI_Wtime()-t_start;

        /* Evaluate implementation 11 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_Sendrecv_pack( request );
        }
        elapsed_time[10] = MPI_Wtime()-t_start;

        /* Evaluate implementation 12 */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_change_sb_pair_Send_Recv_pack( request );
        }
        elapsed_time[11] = MPI_Wtime()-t_start;

        /* Evaluate ADCL B.F amd P.H. */
        /* So far, ADCL will behace according to the config.adcl file */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_Request_start( request );
        }
        elapsed_time[12] = MPI_Wtime()-t_start;
        /* Get winning implementation name */
        ADCL_Request_get_curr_function ( request, &winner_name, NULL, NULL, NULL, NULL);
        /* Get winning implementation number */
        winners[i][0] = winner_name2num(winner_name);

        /* Evaluate ADCL P.H */
        t_start = MPI_Wtime();
        for ( it=0; it<NB_OF_ITERATIONS; it++ ) {
             ADCL_Request_start( request );
        }
        elapsed_time[13] = MPI_Wtime()-t_start;
        /* Get winning implementation name */
        ADCL_Request_get_curr_function ( request, &winner_name, NULL, NULL, NULL, NULL);
        /* Get winning implementation number */
        winners[i][1] = winner_name2num(winner_name);

        MPI_Allreduce ( &elapsed_time, &g_elapsed_time[i], 14 , MPI_DOUBLE, MPI_MAX , MPI_COMM_WORLD);
        if(rank == 0) {
#ifdef VERBOSE
            /* Printing the timing for each implementation and ADCL */
            for(j=0;j<12;j++) {
                printf("Elapsed time using f%d:%s is %f\n",j,impl_names[j],g_elapsed_time[i][j]);
	    }
#endif
            printf("Winner using ADCL B.F. is f%d:%s\nWinner using ADCL P.H. is f%d:%s\n", 
                   winners[i][0], impl_names[winners[i][0]], winners[i][1], impl_names[winners[i][1]] );
            /* Cluster implementations */
            cluster_implementations(g_elapsed_time[i], impl_classes[i]);
	}

        ADCL_Request_free ( &request );
        ADCL_Vector_free ( &vec );
        ADCL_Vmap_free ( &vmap );
    }

    ADCL_Topology_free ( &topo );
    MPI_Comm_free ( &cart_comm );

    /* Processing the results */
    if(rank == 0) {
        /* Comparaison between problem sizes */
        for(i=0; i<NB_OF_SIZES; i++) {
            for (j=0; j<NB_OF_SIZES; j++) {
                distance[j] = compute_distance(i,j);
#ifdef VERBOSE
                printf("The distance between problems %d and %d is %f\n",i,j,distance[2*j]);
#endif
                relation[j] = 0;
                /* Is the winner of pb size i among the best impl of pb size j ? */
                for(k=0;k<NB_OF_IMPL;k++) {
                    if ( (winners[i][0]==k) && (impl_classes[j][k] == BEST_CLASS) ) {
                        relation[j] = 1;
#ifdef VERBOSE
                        printf("similar pb sizes: %d can help optimizing %d\n",i,j);
#endif
		    }
		}
            }
            dmax = find_dmax(distance,relation);
            printf( "Max distance for Pb size %dX%dX%d is %f\n",ProblemSizes[i][0],
                    ProblemSizes[i][1], ProblemSizes[i][2], dmax);
        }
    }
   
exit: 
    ADCL_Finalize ();
    MPI_Finalize ();
    return 0;
}
示例#4
0
文件: pgeom.c 项目: orbeckst/pgeom
int main (int argc, char *argv[]) {
  static char usage[] = {
      "Calculate positions of pseudo-atoms in a model for a transmembrane channel and\n" 
      "write output to FILE or pore.pdb and pore.itp.\n\n"
      "  -h\t\t show help\n"
      "  -v\t\t be verbose (= -debuglevel 30 )\n"
      "  -debug <NUM>\t set debuglevel (0..100)\n"
      "  -spec <NUM>\t default species id\n"
      "  -showspec\t show hard coded species\n\n"
      "  -o FILE\t pdb coordinate file\n"
      "  -s FILE\t itp topology file\n"
      "\n"
      "  -f <file>\t read pore description from file (see below)\n"
      "  -R <r>\t Outer radius of the model\n"
      "  -P <r> <l>\t Pore region: inner radius and length\n"
      "  -M <r> <l>\t Mouth region: largest inner radius and length\n"
      "  -b dmin dmax g_min g_max   (repeatable)\n"
      "\t\tform bonds with angle gamma when atoms are no further apart\n"
      "\t\tthan dmax Ang and g_min <= gamma <= g_max, g from [0°..90°] )\n"
      "  -c\t\t only write connectivity to output, no bond length or kB, kA\n" 
      "  -x\t\t neither connectivity nor bond length to output (isolated atoms)\n" 
      "  -kB <c>\t Force constant of bonds, in kJ mol^-1 nm^-2\n"
      "  -kA <c>\t Force constant of angles, in kJ mol^-1 rad^-2\n"
      "  -cc\t\t Center ccordinates on cavitybox, not on unitcell\n"
      "\n"
      "Pore volume calculation (setting any of these switches on profile calculation):\n"
      "In order to enable volume calculation, set -volume explicitly!\n"
      "ATTENTION: all these LENGTHs are in NANO METRE not Angstrom !\n"
      "  -profile [<file>]  calculate the profile in addition to the volume\n"
      "  -z1, -z2 <z>       profile between z1 and z2\n"
      "  -Rmax <r>          integrate out to Rmax (also use for the total volume\n"
      "                     integration if -profile is set)\n"
      "  -npoints <N>       number of points per dimension in the integrals\n"
      "  -T temp            Temperature in Kelvin [300]\n"
      "  -wca               If set, only use the repulsive part of the Lennard-Jones\n"
      "                     potential (split after Weeks, Chandler & Andersen [1971])\n"
      "  -plot              xfarbe output of the potential in z slices\n"
      "  -nzplot            number of plot slices \n"
      "\nDescription of the input file:\n"
      "------------------------------\n"
      "Instead of using -R (RADIUS), -M (MOUTH), and -P (PORE) one can describe the system\n"
      "in a more flexible manner with a geometry in put file. It can contain up to "
      "MAXDOMAINS domains (i.e. MOUTH and PORE lines). Allowed lines:\n"
      "# comment (skipped)\n"
      "# RADIUS is the global outer radius (in Angstrom)  of the cylinder\n"
      "RADIUS r_outer\n"
      "# domain type and radius at the upper and lower end of the domain;\n"
      "# r_lower of domain i and r_upper of domain i+1 are typically identical\n"
      "MOUTH r_upper r_lower length [species]\n"
      "PORE  r_upper r_lower length [species]\n"

      
  };
  int i, n_atoms, n_bonds, n_angles, n_bc;
  int error;
  real vol;
  FILE *fp;

  /* 
     segmentation fault if arrays to large 
     --->> 
           now that I have learned to  calloc I should rewrite this 
           on purely aesthetical grounds !
     <<---- 
  */
  struct pdb_ATOM model[TOTALSITES];
  struct itp_bond bonds[MAXBONDS]; 
  struct itp_angle angles[MAXANGLES];
  struct geom geometry;
  struct std_input in;
  struct potpars  potential = {
    NULL,
    TEMPERATURE,
    NFREEDOM_SPC,
    CSIX_OW_MTH, CTWELVE_OW_MTH, 0.0,
    0, NULL, NULL,
    N_GAUSSLEG
  };
  struct pprofile profile = {
    "LJprofile.dat",
    FALSE,
    FALSE,
    POT_PLOT_SLICES,
    NULL,
    NZPROF,
    1.5,
    -2,2,
    NULL
  };

  /* argument processing */
  /* *** no sanity checks *** */

  n_atoms  = 0;  /* number of sites ('atoms') in the model */
  n_bonds  = 0;  /* number of bonds */
  n_angles = 0;  /* number of angles between bonds */
  n_bc     = 0;  /* number of constraint conditions for generating bonds */

  if (argc < 2) {
    printf("Running with default values.\n\nType %s -h for help.\n", argv[0]);
    debuglevel = IMPORTANT;
  };

  /* initialize defaults */
  in = default_input ();
  potential.u1 = vljcyl;     /* use the full Lennard-Jones potential in
                               the configurational volume calculations
                               by default */
  profile.pp = &potential;

  /* rudimentary opt-processing.. yarch */
  for (i = 1; i < argc; i++)
    {
      if (!strcmp(argv[i], "-debug")) { 
	debuglevel = atoi(argv[++i]);
      } else if (!strcmp(argv[i], "-v")) {
	debuglevel = VERBOSE; 
      } else if (!strcmp(argv[i], "-h")) {
	print_usage(argv[0],usage);
	exit(1);
      } else if (!strcmp(argv[i], "-showspec")) {
	print_species ();
	exit(1);
      } else if (!strcmp(argv[i], "-o")) {
	in.coordfile = argv[++i]; 
      } else if (!strcmp(argv[i], "-s")) {
	in.topofile = argv[++i];
      } else if (!strcmp(argv[i], "-f")) {
	in.datafile = argv[++i]; 
      } else if (!strcmp(argv[i], "-R")) {
	in.r_outer = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-M")) {
	in.r_mouth = atof(argv[++i]);
	in.l_mouth = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-P")) {
	in.r_pore = atof(argv[++i]);
	in.l_pore = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-spec")) {
	in.specid = atoi(argv[++i]);
      } else if (!strcmp(argv[i], "-b")) {
	if (n_bc > MAXBONDCONSTRAINTS) {
	  fatal_error (1,
		       "Error: too many bond constraints, maximum is %d.\n",  
		       MAXBONDCONSTRAINTS);
	}
	in.bc[n_bc].serial    = n_bc;
	in.bc[n_bc].dmin      = atof(argv[++i]);
	in.bc[n_bc].dmax      = atof(argv[++i]);
	in.bc[n_bc].gamma_min = atof(argv[++i]);
	in.bc[n_bc].gamma_max = atof(argv[++i]);
	in.n_bc               = ++n_bc;
      } else if (!strcmp(argv[i], "-c")) {
	in.connectonly  = TRUE;
      } else if (!strcmp(argv[i], "-x")) {
	in.atomsonly    = TRUE;
      } else if (!strcmp(argv[i], "-cc")) {
	in.shiftcbox    = TRUE;
      } else if (!strcmp(argv[i], "-kB")) {
	in.k_bond  = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-kA")) {
	in.k_angle = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-volume")) {
	profile.bSet = TRUE;
      } else if (!strcmp(argv[i], "-z1")) {
	profile.bSet = TRUE;
	profile.z1 = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-z2")) {
	profile.bSet = TRUE;
	profile.z2 = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-Rmax")) {
	profile.bSet = TRUE;
	profile.Rmax = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-profile")) {
	profile.bSet = TRUE;
	if (i < argc-1 && argv[i+1][0] != '-') 
	  strncpy(profile.fn,argv[++i],STRLEN);
      } else if (!strcmp(argv[i], "-npoints")) {
	potential.ngaussleg = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-T")) {
	potential.Temp = atof(argv[++i]);
      } else if (!strcmp(argv[i], "-wca")) {
	potential.u1 = vRljcyl;
      } else if (!strcmp(argv[i], "-plot")) {
	profile.bPlot = TRUE;
      } else if (!strcmp(argv[i], "-nzplot")) {
	profile.bPlot = TRUE;
	profile.nzplot = atoi(argv[++i]);
      } else {
	mesg(OFF,"Unknown option: %s",argv[i]);
      };
    };

  mesg (ALL, "TOTALSITES %d\n", TOTALSITES);
  mesg (ALL,
   "MAXBONDS %d\nsizeof struct bond %d, sizeof bonds[] %d\n", 
    MAXBONDS, sizeof (struct itp_bond), sizeof (bonds));
  mesg (ALL, 
   "MAXANGLES %d\nsizeof struct angle %d, sizeof angles[] %d\n", 
    MAXANGLES, sizeof (struct itp_angle), sizeof (angles));



  error = input_geom (&in, &geometry);
  setup_domain (&geometry);
  unitcell  (&geometry);
  cavitybox (&geometry);

  n_atoms  = do_coordinates (model, &geometry);

  if (!geometry.atomsonly) {
    n_bonds  = do_bonds (bonds, model, &geometry);
    n_angles = do_angles (angles, bonds, &geometry);
  } else {
    n_bonds = n_angles = 0;
  }

  print_geom (&geometry);    
  
  mesg (WARN, "\nNumber of sites:  %d", n_atoms);
  if (!geometry.atomsonly) {
    mesg (WARN, 
    "Number of bonds:  %d within max cut-off %5.2f Ang (no double-counting)", 
	n_bonds, find_dmax (geometry.bc, geometry.nbc));
    mesg (WARN, "Number of angles: %d (no double-counting)\n", n_angles);
  }

  center (model, &geometry);
  
  error = write_topology (model, bonds, angles, &geometry);
  error = write_pdb (model, bonds, &geometry);

  /* 
     calculate pore volume, based on J. S. Rowlinson, J Chem Soc,
     Faraday Trans. 2, 82 (1986), 1801, (which didnt really work), and
     discussion with Andrew Horsefield.  */

  if (profile.bSet) {
    vol = volume(&potential,model,geometry.domain[1],&profile);

    /* pore profile (already calculated in volume ) */
    fp=fopen(profile.fn,"w");
    if (fp) {
      for(i=0;i<NZPROF;i++) {
        fprintf(fp,"%f  %f\n",profile.r[i][0],profile.r[i][1]);
      }
      fclose(fp);
    }
    free(profile.r);
  }

  return error < 0 ? 1 : 0;
};