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

📄 greq1.c

📁 mpi并行计算的c++代码 可用vc或gcc编译通过 可以用来搭建并行计算试验环境
💻 C
字号:
/* -*- Mode: C; c-basic-offset:4 ; -*- *//* * *  (C) 2003 by Argonne National Laboratory. *      See COPYRIGHT in top-level directory. */#include "mpi.h"#include <stdio.h>#include "mpitest.h"static char MTEST_Descrip[] = "Simple test of generalized requests";int query_fn( void *extra_state, MPI_Status *status ){    /* Set a default status */    status->MPI_SOURCE = MPI_UNDEFINED;    status->MPI_TAG    = MPI_UNDEFINED;    MPI_Status_set_cancelled( status, 0 );    MPI_Status_set_elements( status, MPI_BYTE, 0 );    return 0;}int free_fn( void *extra_state ){    int *b = (int *)extra_state;    if (b) *b = *b - 1;    /* The value returned by the free function is the error code       returned by the wait/test function */    return 0;}int cancel_fn( void *extra_state, int complete ){    return 0;}/* * This is a very simple test of generalized requests.  Normally, the * MPI_Grequest_complete function would be called from another routine, * often running in a separate thread.  This simple code allows us to * check that requests can be created, tested, and waited on in the * case where the request is complete before the wait is called.   * * Note that MPI did *not* define a routine that can be called within * test or wait to advance the state of a generalized request.   * Most uses of generalized requests will need to use a separate thread. */int main( int argc, char *argv[] ){    int errs = 0;    int counter, flag;    MPI_Status    status;    MPI_Request   request;    MTest_Init( &argc, &argv );    MPI_Grequest_start( query_fn, free_fn, cancel_fn, NULL, &request );        MPI_Test( &request, &flag, &status );    if (flag) {	errs++;	fprintf( stderr, "Generalized request marked as complete\n" );    }    MPI_Grequest_complete( request );    MPI_Wait( &request, &status );    counter = 1;    MPI_Grequest_start( query_fn, free_fn, cancel_fn, &counter, &request );    MPI_Grequest_complete( request );    MPI_Wait( &request, MPI_STATUS_IGNORE );        if (counter) {	errs++;	fprintf( stderr, "Free routine not called, or not called with extra_data" );    }    MTest_Finalize( errs );    MPI_Finalize();    return 0;}

⌨️ 快捷键说明

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