⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contents.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (ntypes != 1) errs++;    if (combiner != MPI_COMBINER_INDEXED) errs++;    if (verbose) {        if (nints != 7) fprintf(stderr, "nints = %d; should be 7\n", nints);	if (nadds != 0) fprintf(stderr, "nadds = %d; should be 0\n", nadds);	if (ntypes != 1) fprintf(stderr, "ntypes = %d; should be 1\n", ntypes);	if (combiner != MPI_COMBINER_INDEXED)	    fprintf(stderr, "combiner = %s; should be indexed\n",		    combiner_to_string(combiner));    }    ints = malloc(nints * sizeof(*ints));    if (nadds) adds = malloc(nadds * sizeof(*adds));    types = malloc(ntypes *sizeof(*types));    err = MPI_Type_get_contents(parent_type,				nints,				nadds,				ntypes,				ints,				adds,				types);    if (ints[0] != s_count) errs++;    if (ints[1] != s_blocklengths[0]) errs++;    if (ints[2] != s_blocklengths[1]) errs++;    if (ints[3] != s_blocklengths[2]) errs++;    if (ints[4] != s_displacements[0]) errs++;    if (ints[5] != s_displacements[1]) errs++;    if (ints[6] != s_displacements[2]) errs++;    if (types[0] != MPI_INT) errs++;    if (verbose) {	if (ints[0] != s_count) fprintf(stderr, "count = %d; should be %d\n", ints[0], s_count);	if (ints[1] != s_blocklengths[0]) fprintf(stderr, "blocklength[0] = %d; should be %d\n", ints[1], s_blocklengths[0]);	if (ints[2] != s_blocklengths[1]) fprintf(stderr, "blocklength[1] = %d; should be %d\n", ints[2], s_blocklengths[1]);	if (ints[3] != s_blocklengths[2]) fprintf(stderr, "blocklength[2] = %d; should be %d\n", ints[3], s_blocklengths[2]);	if (ints[4] != s_displacements[0]) fprintf(stderr, "displacement[0] = %d; should be %d\n", ints[4], s_displacements[0]);	if (ints[5] != s_displacements[1]) fprintf(stderr, "displacement[1] = %d; should be %d\n", ints[5], s_displacements[1]);	if (ints[6] != s_displacements[2]) fprintf(stderr, "displacement[2] = %d; should be %d\n", ints[6], s_displacements[2]);	if (types[0] != MPI_INT) fprintf(stderr, "type[0] does not match\n");    }    free(ints);    if (nadds) free(adds);    free(types);    MPI_Type_free( &parent_type );    return errs;}/* indexed_of_vectors_test() * * Builds an indexed type of vectors of ints. * * MPICH1 fails this test because it converts the vectors into hvectors. * * Returns the number of errors encountered. */int indexed_of_vectors_test(void){    MPI_Datatype inner_vector, inner_vector_copy;    MPI_Datatype outer_indexed;        int i_count = 3, i_blocklengths[3] = { 3, 2, 1 };    int i_displacements[3] = { 10, 20, 30 };    int nints, nadds, ntypes, combiner, *ints;    MPI_Aint *adds = NULL;    MPI_Datatype *types;    int err, errs = 0;    /* set up type */    err = MPI_Type_vector(2,			  1,			  2,			  MPI_INT,			  &inner_vector);    if (err != MPI_SUCCESS) {	if (verbose) fprintf(stderr, "error in MPI call; aborting after %d errors\n",			     errs+1);	return errs+1;    }    err = MPI_Type_indexed(i_count,			   i_blocklengths,			   i_displacements,			   inner_vector,			   &outer_indexed);    if (err != MPI_SUCCESS) {	if (verbose) fprintf(stderr, "error in MPI call; aborting after %d errors\n",			     errs+1);	return errs+1;    }    /* decode outer vector (get envelope, then contents) */    err = MPI_Type_get_envelope(outer_indexed,				&nints,				&nadds,				&ntypes,				&combiner);    if (err != MPI_SUCCESS) {	if (verbose) fprintf(stderr, "error in MPI call; aborting after %d errors\n",			     errs+1);	return errs+1;    }    if (nints != 7) errs++;    if (nadds != 0) errs++;    if (ntypes != 1) errs++;    if (combiner != MPI_COMBINER_INDEXED) errs++;    if (verbose) {        if (nints != 7) fprintf(stderr, "nints = %d; should be 7\n", nints);	if (nadds != 0) fprintf(stderr, "nadds = %d; should be 0\n", nadds);	if (ntypes != 1) fprintf(stderr, "ntypes = %d; should be 1\n", ntypes);	if (combiner != MPI_COMBINER_INDEXED)	    fprintf(stderr, "combiner = %s; should be indexed\n",		    combiner_to_string(combiner));    }    if (errs) {	if (verbose) fprintf(stderr, "aborting after %d errors\n", errs);	return errs;    }    ints = malloc(nints * sizeof(*ints));    if (nadds) adds = malloc(nadds * sizeof(*adds));    types = malloc(ntypes * sizeof(*types));    /* get contents of outer vector */    err = MPI_Type_get_contents(outer_indexed,				nints,				nadds,				ntypes,				ints,				adds,				types);    if (ints[0] != i_count) errs++;    if (ints[1] != i_blocklengths[0]) errs++;    if (ints[2] != i_blocklengths[1]) errs++;    if (ints[3] != i_blocklengths[2]) errs++;    if (ints[4] != i_displacements[0]) errs++;    if (ints[5] != i_displacements[1]) errs++;    if (ints[6] != i_displacements[2]) errs++;    if (verbose) {	if (ints[0] != i_count) fprintf(stderr, "count = %d; should be %d\n", ints[0], i_count);	if (ints[1] != i_blocklengths[0]) fprintf(stderr, "blocklength[0] = %d; should be %d\n", ints[1], i_blocklengths[0]);	if (ints[2] != i_blocklengths[1]) fprintf(stderr, "blocklength[1] = %d; should be %d\n", ints[2], i_blocklengths[1]);	if (ints[3] != i_blocklengths[2]) fprintf(stderr, "blocklength[2] = %d; should be %d\n", ints[3], i_blocklengths[2]);	if (ints[4] != i_displacements[0]) fprintf(stderr, "displacement[0] = %d; should be %d\n", ints[4], i_displacements[0]);	if (ints[5] != i_displacements[1]) fprintf(stderr, "displacement[1] = %d; should be %d\n", ints[5], i_displacements[1]);	if (ints[6] != i_displacements[2]) fprintf(stderr, "displacement[2] = %d; should be %d\n", ints[6], i_displacements[2]);    }    if (errs) {	if (verbose) fprintf(stderr, "aborting after %d errors\n", errs);	return errs;    }    inner_vector_copy = types[0];    free(ints);    if (nadds) free(adds);    free(types);    /* decode inner vector */    err = MPI_Type_get_envelope(inner_vector_copy,				&nints,				&nadds,				&ntypes,				&combiner);    if (err != MPI_SUCCESS) {	if (verbose) fprintf(stderr, "error in MPI call; aborting after %d errors\n",			     errs+1);	return errs+1;    }    if (nints != 3) errs++;    if (nadds != 0) errs++;    if (ntypes != 1) errs++;    if (combiner != MPI_COMBINER_VECTOR) errs++;    if (verbose) {	if (nints != 3) fprintf(stderr, "inner vector nints = %d; should be 3\n",				nints);	if (nadds != 0) fprintf(stderr, "inner vector nadds = %d; should be 0\n",				nadds);	if (ntypes != 1) fprintf(stderr, "inner vector ntypes = %d; should be 1\n",				 ntypes);	if (combiner != MPI_COMBINER_VECTOR)	    fprintf(stderr, "inner vector combiner = %s; should be vector\n",		    combiner_to_string(combiner));    }    if (errs) {	if (verbose) fprintf(stderr, "aborting after %d errors\n", errs);	return errs;    }    ints = malloc(nints * sizeof(*ints));    if (nadds) adds = malloc(nadds * sizeof(*adds));    types = malloc(ntypes * sizeof(*types));    err = MPI_Type_get_contents(inner_vector_copy,				nints,				nadds,				ntypes,				ints,				adds,				types);    if (ints[0] != 2) errs++;    if (ints[1] != 1) errs++;    if (ints[2] != 2) errs++;    if (verbose) {	if (ints[0] != 2) fprintf(stderr, "inner vector count = %d; should be 2\n",				  ints[0]);	if (ints[1] != 1) fprintf(stderr,				  "inner vector blocklength = %d; should be 1\n",				  ints[1]);	if (ints[2] != 2) fprintf(stderr, "inner vector stride = %d; should be 2\n",				  ints[2]);    }    if (errs) {	if (verbose) fprintf(stderr, "aborting after %d errors\n", errs);	return errs;    }    free(ints);    if (nadds) free(adds);    free(types);    MPI_Type_free( &inner_vector_copy );    MPI_Type_free( &inner_vector );    MPI_Type_free( &outer_indexed );    return 0;}#ifdef HAVE_MPI_TYPE_CREATE_STRUCT/* struct_of_basics_test(void) * * There's nothing simple about structs :).  Although this is an easy one. * * Returns number of errors encountered. * * NOT TESTED. */int struct_of_basics_test(void){    MPI_Datatype parent_type;    int s_count = 3, s_blocklengths[3] = { 3, 2, 1 };    MPI_Aint s_displacements[3] = { 10, 20, 30 };    MPI_Datatype s_types[3] = { MPI_CHAR, MPI_INT, MPI_FLOAT };    int nints, nadds, ntypes, combiner, *ints;    MPI_Aint *adds = NULL;    MPI_Datatype *types;    int err, errs = 0;    /* set up type */    err = MPI_Type_create_struct(s_count,				 s_blocklengths,				 s_displacements,				 s_types,				 &parent_type);    /* decode */    err = MPI_Type_get_envelope(parent_type,				&nints,				&nadds,				&ntypes,				&combiner);    if (nints != 4) errs++;    if (nadds != 3) errs++;    if (ntypes != 3) errs++;    if (combiner != MPI_COMBINER_STRUCT) errs++;    if (verbose) {        if (nints != 4) fprintf(stderr, "nints = %d; should be 3\n", nints);	if (nadds != 3) fprintf(stderr, "nadds = %d; should be 0\n", nadds);	if (ntypes != 3) fprintf(stderr, "ntypes = %d; should be 3\n", ntypes);	if (combiner != MPI_COMBINER_STRUCT)	    fprintf(stderr, "combiner = %s; should be struct\n",		    combiner_to_string(combiner));    }    ints = malloc(nints * sizeof(*ints));    adds = malloc(nadds * sizeof(*adds));    types = malloc(ntypes *sizeof(*types));    err = MPI_Type_get_contents(parent_type,				nints,				nadds,				ntypes,				ints,				adds,				types);    if (ints[0] != s_count) errs++;    if (ints[1] != s_blocklengths[0]) errs++;    if (ints[2] != s_blocklengths[1]) errs++;    if (ints[3] != s_blocklengths[2]) errs++;    if (adds[0] != s_displacements[0]) errs++;    if (adds[1] != s_displacements[1]) errs++;    if (adds[2] != s_displacements[2]) errs++;    if (types[0] != s_types[0]) errs++;    if (types[1] != s_types[1]) errs++;    if (types[2] != s_types[2]) errs++;    if (verbose) {	if (ints[0] != s_count) fprintf(stderr, "count = %d; should be %d\n", ints[0], s_count);	if (ints[1] != s_blocklengths[0]) fprintf(stderr, "blocklength[0] = %d; should be %d\n", ints[1], s_blocklengths[0]);	if (ints[2] != s_blocklengths[1]) fprintf(stderr, "blocklength[1] = %d; should be %d\n", ints[2], s_blocklengths[1]);	if (ints[3] != s_blocklengths[2]) fprintf(stderr, "blocklength[2] = %d; should be %d\n", ints[3], s_blocklengths[2]);	if (adds[0] != s_displacements[0]) fprintf(stderr, "displacement[0] = %d; should be %d\n", adds[0], s_displacements[0]);	if (adds[1] != s_displacements[1]) fprintf(stderr, "displacement[1] = %d; should be %d\n", adds[1], s_displacements[1]);	if (adds[2] != s_displacements[2]) fprintf(stderr, "displacement[2] = %d; should be %d\n", adds[2], s_displacements[2]);	if (types[0] != s_types[0]) fprintf(stderr, "type[0] does not match\n");	if (types[1] != s_types[1]) fprintf(stderr, "type[1] does not match\n");	if (types[2] != s_types[2]) fprintf(stderr, "type[2] does not match\n");    }    free(ints);    free(adds);    free(types);    MPI_Type_free( &parent_type );    return errs;}#endif/* combiner_to_string(combiner) * * Converts a numeric combiner into a pointer to a string used for printing. */char *combiner_to_string(int combiner){    static char c_named[]    = "named";    static char c_contig[]   = "contig";    static char c_vector[]   = "vector";    static char c_hvector[]  = "hvector";    static char c_indexed[]  = "indexed";    static char c_hindexed[] = "hindexed";    static char c_struct[]   = "struct";#ifdef HAVE_MPI2_COMBINERS    static char c_dup[]              = "dup";    static char c_hvector_integer[]  = "hvector_integer";    static char c_hindexed_integer[] = "hindexed_integer";    static char c_indexed_block[]    = "indexed_block";    static char c_struct_integer[]   = "struct_integer";    static char c_subarray[]         = "subarray";    static char c_darray[]           = "darray";    static char c_f90_real[]         = "f90_real";    static char c_f90_complex[]      = "f90_complex";    static char c_f90_integer[]      = "f90_integer";    static char c_resized[]          = "resized";#endif    if (combiner == MPI_COMBINER_NAMED)      return c_named;    if (combiner == MPI_COMBINER_CONTIGUOUS) return c_contig;    if (combiner == MPI_COMBINER_VECTOR)     return c_vector;    if (combiner == MPI_COMBINER_HVECTOR)    return c_hvector;    if (combiner == MPI_COMBINER_INDEXED)    return c_indexed;    if (combiner == MPI_COMBINER_HINDEXED)   return c_hindexed;    if (combiner == MPI_COMBINER_STRUCT)     return c_struct;#ifdef HAVE_MPI2_COMBINERS    if (combiner == MPI_COMBINER_DUP)              return c_dup;    if (combiner == MPI_COMBINER_HVECTOR_INTEGER)  return c_hvector_integer;    if (combiner == MPI_COMBINER_HINDEXED_INTEGER) return c_hindexed_integer;    if (combiner == MPI_COMBINER_INDEXED_BLOCK)    return c_indexed_block;    if (combiner == MPI_COMBINER_STRUCT_INTEGER)   return c_struct_integer;    if (combiner == MPI_COMBINER_SUBARRAY)         return c_subarray;    if (combiner == MPI_COMBINER_DARRAY)           return c_darray;    if (combiner == MPI_COMBINER_F90_REAL)         return c_f90_real;    if (combiner == MPI_COMBINER_F90_COMPLEX)      return c_f90_complex;    if (combiner == MPI_COMBINER_F90_INTEGER)      return c_f90_integer;    if (combiner == MPI_COMBINER_RESIZED)          return c_resized;#endif        return NULL;}int parse_args(int argc, char **argv){#ifdef HAVE_GET_OPT    int ret;    while ((ret = getopt(argc, argv, "v")) >= 0)    {	switch (ret) {	    case 'v':		verbose = 1;		break;	}    }#else#endif    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -