ga_mutex1.c

来自「The example for Boor USING MPI2」· C语言 代码 · 共 37 行

C
37
字号
#include "ga.h"/* Instead of using a static variable, we could attach these to    a communicator, using a communicator attribute */static MPI_Win *GA_mutex_wins = 0;static int      GA_mutex_nwins = 0;int ga_create_mutexes( int num ){    int size, nwin, i;    MPI_Comm_size( MPI_COMM_WORLD, &size );        nwin = (num + size - 1) / size;        GA_mutex_wins = (MPI_Win *)malloc( nwin * sizeof(MPI_Win) );    if (!GA_mutex_wins) return 1;        for (i=0; i<nwin; i++) {	if (num < size) size = num;	MPE_Mutex_create( MPI_COMM_WORLD, size, &GA_mutex_wins[i] );	num -= size;    }        GA_mutex_nwins = nwin;    return 0;}void ga_lock( int n ){    int size, rank, win_num;    MPI_Comm_size( MPI_COMM_WORLD, &size );    win_num = n / size;    rank    = n % size;    MPE_Mutex_lock( rank, GA_mutex_wins[win_num] );}

⌨️ 快捷键说明

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