小编Mik*_*ail的帖子

为什么我所有的mpi线程都是大师?

我开始使用MPI并编写了一个快速演示程序:

int main(int argc, char** argv)
{
    MPI_Init(&argc, &argv);
    int myRank = MPI_Comm_rank(MPI_COMM_WORLD, &myRank);
    if (myRank) {
    cout << "slave" << endl;
    }
    else {
    cout << "master" << endl;
    }
    MPI_Finalize();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我使用以下命令运行它:

aprun -n 4 test
Run Code Online (Sandbox Code Playgroud)

我的输出是

master
master
master
master
Run Code Online (Sandbox Code Playgroud)

我期待着类似的东西

slave
master
slave
slave
Run Code Online (Sandbox Code Playgroud)

为什么会这样?为什么我的所有主题都是主人?

c++ mpi

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

预先简化扩展变量

我正在使用一些我需要运行的MPI代码mpirun.

我正在使用一个已经存在的shell脚本,我希望在现有的行前面添加.

所以梦想是:

app=mpirun $(app)
Run Code Online (Sandbox Code Playgroud)

我知道可以使用+ =附加到变量,但是我可以预先添加吗?

makefile gnu-make

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

跨线程的unique_lock?

我在概念化如何unique_lock跨线程操作时遇到了一些麻烦.我试图做一个快速的例子来重新创建我通常会使用的东西condition_variable.

#include <mutex>
#include <thread>
using namespace std;
mutex m;
unique_lock<mutex>* mLock;
void funcA()
{
    //thread 2
    mLock->lock();//blocks until unlock?Access violation reading location 0x0000000000000000.
}

int _tmain(int argc, _TCHAR* argv[])
{
    //thread 1
    mLock = new unique_lock<mutex>(m);
    mLock->release();//Allows .lock() to be taken by a different thread?
    auto a = std::thread(funcA);
    std::chrono::milliseconds dura(1000);//make sure thread is running
    std::this_thread::sleep_for(dura);
    mLock->unlock();//Unlocks thread 2's lock?
    a.join();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ concurrency locking c++11

2
推荐指数
2
解决办法
3879
查看次数

GameBoy ISA(编写模拟器)

我正在使用 C 语言开发 GameBoy 模拟器。现在我正在处理 CPU.c 文件,但我对此处列出的一些说明感到有些困惑:

http://realboyemulator.files.wordpress.com/2013/01/gbcpuman.pdf

如果您参考上述 PDF 的第 66 页,并查看与操作码 0x7E -- LD,R1,R2 相对应的指令,我对这不是结构很好奇..

GB 有 8 个 8 位寄存器,A、B、C、D、E、F、H、L。16 位寄存器可以通过连接两个:AF、BC、DE、HL 来构成。

我对操作码 0x7E 感到困惑,因为它看起来像是试图将 16 位值 (HL) 存储到 8 位寄存器 (A) 中。

LD,A,(HL)

我误解了这份文件吗?有人可以解释为什么会存在这样的指令吗?难道不能只用LD,A,L代替吗?

assembly z80 emulation cpu-registers gameboy

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

自定义类的STL容器不包含成员的值

我在使用自定义类的容器时遇到问题.每次我尝试创建一个对象并推送它时,推送对象中的成员变量显示为零.因此,myConnection.value显示为0而不是其值.我怀疑我的拷贝构造函数有问题.

全球定义

vector<connection> Connections;
Run Code Online (Sandbox Code Playgroud)

麻烦的地方

    while ( dataInput.good() )
{
    getline (dataInput,line);
    sscanf(line.c_str(),"%lg %lg %d %d",&k,&order,&final,&initial);
    printf("%lg %lg %d %d\n",k,order,final,initial);//Looks Good
    Connections.push_back(connection(k,order,final,initial));
    printf("%lg %lg %s %d\n",Connections[i].k,Connections[i].order,Connections[i].to,Connections[i].from);//Everything is zero!?
    i++;
}
Run Code Online (Sandbox Code Playgroud)

Connection.cpp

#include "../include/connection.h"
#include <stdio.h>
connection::connection(double kin, double orderin, int fromin,int toin)
{
    k=kin;
    order=orderin;
    from = fromin;
    to=toin;
printf("%d %d %i %i\n",kin,orderin,fromin,toin);

}

connection::~connection()
{
    //dtor
}

connection::connection(const connection &c)
{
    connection(c.k,c.order,c.from,c.to);
}
Run Code Online (Sandbox Code Playgroud)

Connection.h

#ifndef CONNECTION_H
#define CONNECTION_H


class connection
{
public:
    connection(double, double, int,int);
    connection(const connection& c);
    virtual …
Run Code Online (Sandbox Code Playgroud)

c++ stl class vector copy-constructor

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

为什么Cmake总是选择GCC?

由于我无法完全理解的原因,Cmake awlays在编译软件时选择了GNU编译器工具集.

我的环境看起来像这样:

which cc
/opt/cray/xt-asyncpe/4.9/bin/cc
which CC
/opt/cray/xt-asyncpe/4.9/bin/CC
echo $CC
/opt/cray/xt-asyncpe/4.9/bin/cc
echo $CXX
/opt/cray/xt-asyncpe/4.9/bin/CC
Run Code Online (Sandbox Code Playgroud)

但是当我使用cmake时,我得到了这个

Using existing /opt/cmake/2.8.4/bin/cmake
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- …
Run Code Online (Sandbox Code Playgroud)

cmake environment-variables cray

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

这是参考还是价值?

我编写C#代码的经验很少,但我想为我的一些代码制作一个强大的Windows GUI.我想知道以下代码是通过值还是通过引用传递的.具体来说,如果bytes[]在传递给神秘之前被复制?我需要在extern中使用explicate ref语句吗?

 [DllImport("unSHA.dll", CallingConvention = CallingConvention.Cdecl)]
 private static extern void time(byte[] bytes);
Run Code Online (Sandbox Code Playgroud)

c# pass-by-reference

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

是否有可以忽略函数的gcc编译指示?

我想要一个完全忽略函数的命令.有人曾经给我看过这个命令,但我在手册中找不到它.

void a()
{
return;
}
#pragma gcc_disable
void a ()
{
return q09w8uifsdf
}
#include <stdio.h>
int main ()
{
  a();
}
Run Code Online (Sandbox Code Playgroud)

c c++ gcc

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

OpenGL亮度到颜色映射?

我想知道是否有办法处理OpenGL纹理缓冲区,以便通过我选择的某个公式将灰度值缓冲区转换为rgb值.

我已经有一个功能,它运作良好但输出颜色3矢量.

rgb convertToColor(float value);
Run Code Online (Sandbox Code Playgroud)

我是OpenGL的新手,想知道我应该使用什么样的着色器以及它应该去哪里.我的程序目前循环帧如下:

program1.bind();
program1.setUniformValue("texture", 0);
program1.enableAttributeArray(vertexAttr1);
program1.enableAttributeArray(vertexTexr1);
program1.setAttributeArray(vertexAttr1, vertices.constData());
program1.setAttributeArray(vertexTexr1, texCoords.constData());
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,widthGL,heightGL, GL_LUMINANCE,GL_UNSIGNED_BYTE, &displayBuff[displayStart]);
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
glBindTexture(GL_TEXTURE_2D,0);
//...
Run Code Online (Sandbox Code Playgroud)

着色器

QGLShader *fshader1 = new QGLShader(QGLShader::Fragment, this);
    const char *fsrc1 =
        "uniform sampler2D texture;\n"
        "varying mediump vec4 texc;\n"
        "void main(void)\n"
        "{\n"
        "    gl_FragColor = texture2D(texture, texc.st);\n"
        "}\n";
Run Code Online (Sandbox Code Playgroud)

我试图在matlab中重新创建像imagesc一样的效果,如下图所示: 于imagesc

c++ opengl opengl-3

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

std :: algorithm :: sort的比较器?

vector< pair<size_t, tuple<double,double> >>
sort_indexes(const vector<tuple<double,double>> &v)
//takes a list and prepends the sorted inxdex
{
    // Copy data
    vector< pair<size_t, tuple<double,double> >> idx(v.size());
    for (size_t i = 0; i != idx.size(); ++i)
    {
        idx[i].first=i ;
        idx[i].second=v[i];
    }
    sort(idx.begin(), idx.end(),
        [&v](size_t i1, size_t i2) {return get<0>(v[i1]) < get<0>(v[i2]);}
        );
    return idx;
}
Run Code Online (Sandbox Code Playgroud)

错误看起来像:

1> C:\ Program Files(x86)\ Microsoft Visual Studio 11.0\VC\include\algorithm(3781):错误C2664:'bool sort_indexes :::: operator()(size_t,size_t)const':无法转换参数1从'std :: pair <_Ty1,_Ty2>'到'size_t'

我很困惑,比较器的形式是什么?我认为它应该是返回布尔值的任何东西?和lambda我提供接缝返回一个布尔值?

当我删除比较器时,代码仍然排序,虽然这种效果不合适,因为索引的排序具有可预测的结果.

c++ algorithm

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