小编GBB*_*BBL的帖子

在MPI中订购输出

在一个简单的MPI程序中,我使用了一个大矩阵的列式划分.如何订购输出,使每个矩阵出现在另一个矩阵旁边?我试过这个简单的代码,效果与想要的完全不同:

for(int i=0;i<10;i++)
{
    for(int k=0;k<numprocs;k++)
    {
        if (my_id==k){
            for(int j=1;j<10;j++)
                printf("%d",data[i][j]);
        }
        MPI_Barrier(com);
    }
    if(my_id==0)
        printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

似乎每个进程都有自己的标准输出,因此不可能在没有将所有数据发送到一个将打印输出的主数据的情况下排序行输出.我的猜测是真的吗?或者我做错了什么?

stdout mpi

14
推荐指数
1
解决办法
2万
查看次数

使用not2时,struct vs class作为STL仿函数

Studing STL我写了一个简单的程序来测试仿函数和修饰符.我的问题是关于使用CLASS或STRUCT编写仿函数并尝试使用函数适配器对其进行操作的差异.据我所知,在C++中,CLASS和STRUCT之间的区别在于,在最后一种情况下,成员默认是公共的.这也是我在本网站的答案中多次阅读的内容.所以请解释一下,为什么这段简短的代码无法编译,即使我在尝试使用not2修饰符时声明所有成员(只是函数重载())公开.(我还没有尝试过其他修饰符,例如粘合剂)

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

template <class T>
void print  (T  i) {
    cout << " " << i;
}
// In the manual I read:
// "In C++, a structure is the same as a class except that its members are public by default."
//  So if I declare all members public it should work....

template <class T>
class mystruct : binary_function<T ,T ,bool> {
    public :
    bool operator() (T  i,T …
Run Code Online (Sandbox Code Playgroud)

c++ struct stl class

4
推荐指数
1
解决办法
1614
查看次数

#pragma omp flush在线程之间建立交换数据

你写了一个非常简单的例子,说明如何使用omp flush来交换数据,以生产者 - >消费者的方式,在线程中我发现了一个有趣的行为.

int a=-1;
int flag=1;
int count=0;
#pragma omp parallel  num_threads(2)
{ 
    int TID;
    TID=omp_get_thread_num();
#pragma omp sections 
    {

#pragma omp section /////////// Producer
        {

            for(int i=0; i<9;i++)
            {
                a=i;
#pragma omp flush(a)
                flag=1;
                printf("Producer a: %d  flag:%d  TID %d \n",a,flag,TID);

                while(flag)
                {

#pragma omp flush(flag)

                }

            }
            flag=2;
#pragma omp flush(flag)

        } // end producer

#pragma omp section  /////////// Consumer
        {
            while(1) {
                count++;

                flag=0;
                while(!flag)
                {
#pragma omp flush(flag)
                }
#pragma omp flush(a)
                printf("Consumer a: …
Run Code Online (Sandbox Code Playgroud)

c openmp

3
推荐指数
1
解决办法
5105
查看次数

not2 stl negator

学习STL我试图否定一个没有问题但是有问题的算子.这是一个例子:

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct  mystruct : binary_function<int,int,bool> {
 bool operator() (int i,int j) { return i<j; }
};

template <class T>
class generatore 
{
public:
 generatore (T  start = 0, T  stp = 1) : current(start), step(stp)
 { }
 T  operator() () { return current+=step; }
private:
 T  current;
 T  step;
};


int main () {
 vector<int> first(10);

generate(first.begin(), first.end(), generatore<int>(10,10) ); 
cout << "Smallest element " << *min_element(first.begin(), first.end(),mystruct() ) …
Run Code Online (Sandbox Code Playgroud)

c++ stl

1
推荐指数
1
解决办法
480
查看次数

标签 统计

c++ ×2

stl ×2

c ×1

class ×1

mpi ×1

openmp ×1

stdout ×1

struct ×1