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

📄 allred.c

📁 fortran并行计算包
💻 C
📖 第 1 页 / 共 5 页
字号:
    in = (unsigned short *)malloc( count * sizeof(unsigned short) );    out = (unsigned short *)malloc( count * sizeof(unsigned short) );    sol = (unsigned short *)malloc( count * sizeof(unsigned short) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_MAX, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_MAX\n", rank );    free( in );    free( out );    free( sol );}void e3(void){    unsigned *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned *)malloc( count * sizeof(unsigned) );    out = (unsigned *)malloc( count * sizeof(unsigned) );    sol = (unsigned *)malloc( count * sizeof(unsigned) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_MAX, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED and op MPI_MAX\n", rank );    free( in );    free( out );    free( sol );}void f3(void){    unsigned long *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned long *)malloc( count * sizeof(unsigned long) );    out = (unsigned long *)malloc( count * sizeof(unsigned long) );    sol = (unsigned long *)malloc( count * sizeof(unsigned long) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_MAX, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_LONG and op MPI_MAX\n", rank );    free( in );    free( out );    free( sol );}void g3(void){    float *in, *out, *sol;    int  i, fnderr=0;    in = (float *)malloc( count * sizeof(float) );    out = (float *)malloc( count * sizeof(float) );    sol = (float *)malloc( count * sizeof(float) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_MAX, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_FLOAT and op MPI_MAX\n", rank );    free( in );    free( out );    free( sol );}void h3(void){    double *in, *out, *sol;    int  i, fnderr=0;    in = (double *)malloc( count * sizeof(double) );    out = (double *)malloc( count * sizeof(double) );    sol = (double *)malloc( count * sizeof(double) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = (size - 1 + i);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_MAX, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_DOUBLE and op MPI_MAX\n", rank );    free( in );    free( out );    free( sol );}void a4(void){    int *in, *out, *sol;    int  i, fnderr=0;    in = (int *)malloc( count * sizeof(int) );    out = (int *)malloc( count * sizeof(int) );    sol = (int *)malloc( count * sizeof(int) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_INT, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_INT and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void b4(void){    long *in, *out, *sol;    int  i, fnderr=0;    in = (long *)malloc( count * sizeof(long) );    out = (long *)malloc( count * sizeof(long) );    sol = (long *)malloc( count * sizeof(long) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_LONG, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_LONG and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void c4(void){    short *in, *out, *sol;    int  i, fnderr=0;    in = (short *)malloc( count * sizeof(short) );    out = (short *)malloc( count * sizeof(short) );    sol = (short *)malloc( count * sizeof(short) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_SHORT, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_SHORT and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void d4(void){    unsigned short *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned short *)malloc( count * sizeof(unsigned short) );    out = (unsigned short *)malloc( count * sizeof(unsigned short) );    sol = (unsigned short *)malloc( count * sizeof(unsigned short) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void e4(void){    unsigned *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned *)malloc( count * sizeof(unsigned) );    out = (unsigned *)malloc( count * sizeof(unsigned) );    sol = (unsigned *)malloc( count * sizeof(unsigned) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void f4(void){    unsigned long *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned long *)malloc( count * sizeof(unsigned long) );    out = (unsigned long *)malloc( count * sizeof(unsigned long) );    sol = (unsigned long *)malloc( count * sizeof(unsigned long) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_LONG and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void g4(void){    float *in, *out, *sol;    int  i, fnderr=0;    in = (float *)malloc( count * sizeof(float) );    out = (float *)malloc( count * sizeof(float) );    sol = (float *)malloc( count * sizeof(float) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_FLOAT, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_FLOAT and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void h4(void){    double *in, *out, *sol;    int  i, fnderr=0;    in = (double *)malloc( count * sizeof(double) );    out = (double *)malloc( count * sizeof(double) );    sol = (double *)malloc( count * sizeof(double) );    for (i=0; i<count; i++) { *(in + i) = (rank + i); *(sol + i) = i;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_DOUBLE, MPI_MIN, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_DOUBLE and op MPI_MIN\n", rank );    free( in );    free( out );    free( sol );}void a5(void){    int *in, *out, *sol;    int  i, fnderr=0;    in = (int *)malloc( count * sizeof(int) );    out = (int *)malloc( count * sizeof(int) );    sol = (int *)malloc( count * sizeof(int) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_INT, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_INT and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void b5(void){    long *in, *out, *sol;    int  i, fnderr=0;    in = (long *)malloc( count * sizeof(long) );    out = (long *)malloc( count * sizeof(long) );    sol = (long *)malloc( count * sizeof(long) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_LONG, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_LONG and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void c5(void){    short *in, *out, *sol;    int  i, fnderr=0;    in = (short *)malloc( count * sizeof(short) );    out = (short *)malloc( count * sizeof(short) );    sol = (short *)malloc( count * sizeof(short) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_SHORT, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_SHORT and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void d5(void){    unsigned short *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned short *)malloc( count * sizeof(unsigned short) );    out = (unsigned short *)malloc( count * sizeof(unsigned short) );    sol = (unsigned short *)malloc( count * sizeof(unsigned short) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_SHORT, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_SHORT and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void e5(void){    unsigned *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned *)malloc( count * sizeof(unsigned) );    out = (unsigned *)malloc( count * sizeof(unsigned) );    sol = (unsigned *)malloc( count * sizeof(unsigned) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void f5(void){    unsigned long *in, *out, *sol;    int  i, fnderr=0;    in = (unsigned long *)malloc( count * sizeof(unsigned long) );    out = (unsigned long *)malloc( count * sizeof(unsigned long) );    sol = (unsigned long *)malloc( count * sizeof(unsigned long) );    for (i=0; i<count; i++) { *(in + i) = (rank & 0x1); *(sol + i) = (size > 1);     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_UNSIGNED_LONG, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_UNSIGNED_LONG and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void a6(void){    int *in, *out, *sol;    int  i, fnderr=0;    in = (int *)malloc( count * sizeof(int) );    out = (int *)malloc( count * sizeof(int) );    sol = (int *)malloc( count * sizeof(int) );    for (i=0; i<count; i++) { *(in + i) = 0; *(sol + i) = 0;     *(out + i) = 0; }    MPI_Allreduce( in, out, count, MPI_INT, MPI_LOR, comm );    for (i=0; i<count; i++) { if (*(out + i) != *(sol + i)) {errcnt++; fnderr++;}}    if (fnderr) fprintf( stderr, 	"(%d) Error for type MPI_INT and op MPI_LOR\n", rank );    free( in );    free( out );    free( sol );}void b6(void){    long *in, *out, *sol;    int  i, fnderr=0;    in = (long *)malloc( count * sizeof(long) );

⌨️ 快捷键说明

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