小编Bri*_*ain的帖子

将Billion Integers初始化为值1

在具有32GB DRAM的Linux平台8核CPU上使用c/c ++初始化十亿个整数的优秀posix线程设计是什么?谢谢你的帮助.

c c++ linux performance

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

使用-std = c ++ 0x增加1.53本地日期时间编译器错误

使用g ++版本4.7.2,如果我尝试编译以下内容

#include <boost/date_time/local_time/local_time.hpp> 

class Bar
{
public:

Bar() { tz_db_.load_from_file("/home/date_time_zonespec.csv"); }

private:
    boost::local_time::tz_database tz_db_;
};

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用-std = c ++ 0x我收到以下错误.

In file included from /usr/local/include/boost/date_time/local_time/local_time_types.hpp:18:0,
                 from /usr/local/include/boost/date_time/local_time/local_time.hpp:13,
                 from test.h:4,
                 from test.cpp:1: /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp: In instantiation of ‘bool boost::local_time::custom_time_zone_base<CharT>::has_dst() const [with CharT = char]’: test.cpp:11:1:   required from here /usr/local/include/boost/date_time/local_time/custom_time_zone.hpp:67:30: error: cannot convert ‘const boost::shared_ptr<boost::date_time::dst_day_calc_rule<boost::gregorian::date>
>’ to ‘bool’ in return
Run Code Online (Sandbox Code Playgroud)

如果我不使用c ++ 0x选项,一切都很好.谁能告诉我这里发生了什么?

c++ boost g++ c++11

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

在android中编译boost时出错

我试图根据这个安装boost 1.5到android .

当我编译时,我收到一个错误.这是编译错误的一个片段:

gcc.compile.c++ bin.v2/libs/thread/build/gcc-android4.4.3/release/link-static/runtime-link-    static/threading-multi/pthread/thread.o
<command-line>: warning: "BOOST_FILESYSTEM_VERSION" redefined
<command-line>: warning: this is the location of the previous definition
In file included from ./boost/thread/thread.hpp:17,
             from libs/thread/src/pthread/thread.cpp:11:
./boost/thread/pthread/thread_data.hpp: In member function 'void    boost::thread_attributes::set_stack_size(size_t)':
./boost/thread/pthread/thread_data.hpp:42: error: 'PAGE_SIZE' was not declared in this scope

"../../toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-g++"  -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -pedantic --sysroot=../../platforms/android-9/arch-arm -mthumb -Os -fno-strict-aliasing -O2 -DNDEBUG -g -lstdc++ -I../../sources/cxx-stl/gnu-libstdc++/include -I../../sources/cxx-stl/gnu-libstdc++/libs/armeabi/include -D__GLIBC__ -DBOOST_NO_INTRINSIC_WCHAR_T -DBOOST_FILESYSTEM_VERSION=2 -pthread -Wextra -Wno-long-long -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_CHRONO_STATIC_LINK=1 -DBOOST_FILESYSTEM_VERSION=3 -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_POSIX -DNDEBUG  -I"." -c -o …
Run Code Online (Sandbox Code Playgroud)

c++ android boost

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

关闭python?

当我运行此代码时,我得到这个结果:

15
15
Run Code Online (Sandbox Code Playgroud)

我希望输出应该是

15
17
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.问题是:为什么?

def make_adder_and_setter(x):
    def setter(n):
        x = n

    return (lambda y: x + y, setter)

myadder, mysetter = make_adder_and_setter(5)
print myadder(10)
mysetter(7)
print myadder(10)
Run Code Online (Sandbox Code Playgroud)

python closures python-2.x

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

Python:在赋值错误之前引用的局部变量

我一直有错误

UnboundLocalError:赋值前引用的局部变量'new_speedDx'

在尝试运行以下功能时:

def new_speedD(boid1):
    bposx = boid1[0]
    if bposx < WALL:
        new_speedDx = WALL_FORCE
    elif bposx > WIDTH - WALL:
        new_speedDx = -WALL_FORCE

    bposy = boid1[1]
    if bposy < WALL:
        new_speedDy = WALL_FORCE
    elif bposx > WIDTH - WALL:
        new_speedDy = -WALL_FORCE

    return new_speedDx, new_speedDy
Run Code Online (Sandbox Code Playgroud)

在这个函数中,boid1是一个有4个元素的向量(xpos,ypos,xvelocity,yvelocity),所有大写的变量都是常量(数字).有人知道如何解决这个问题?我在互联网上找到了许多可能的解决方案,但似乎没有任何工作..

python boids

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

Visual Studio无法识别CUDA的“ThreadIdx”

在下面的示例中,Visual StudiothreadIdx用红线突出显示“”。

看起来程序执行成功,所以问题只是VisualStudio中的显示问题。

我怎样才能使 Visual Studio 不再突出显示threadIdx为无效?

我的环境: * 操作系统:Windows7,64位 * VisualStudio2010,CUDA5.5


源代码:

 #include <cuda_runtime.h>
 #include <stdio.h> 
 #include <math.h> 
 #include <cuda.h> 


 #define N 256
 __global__ void matrix_vector_multi_gpu_1_256(float *A_d, float *B_d, float *C_d);
 int main(){
    int i,j;
    float A[N], B[N*N], C[N];
    float *A_d, *B_d, *C_d;

    dim3 blocks(1,1,1);
    dim3 threads(256,1,1);

    for(j=0;j<N;j++){
       for(i=0;i<N;i++){
        B[j*N+i]=((float)j)/256.0;
        }
    }

    for(j=0;j<N;j++){
       C[j]=1.0F;
    }

    cudaMalloc((void**)&A_d, N*sizeof(float));
    cudaMalloc((void**)&B_d, N*N*sizeof(float));
    cudaMalloc((void**)&C_d, N*sizeof(float));

    cudaMemcpy(A_d,A,N*sizeof(float),cudaMemcpyHostToDevice);
    cudaMemcpy(B_d,B,N*N*sizeof(float),cudaMemcpyHostToDevice);
    cudaMemcpy(C_d,C,N*sizeof(float),cudaMemcpyHostToDevice);

    matrix_vector_multi_gpu_1_256<<<blocks,threads>>>(A_d,B_d,C_d);
    cudaMemcpy(A,A_d,N*sizeof(float),cudaMemcpyDeviceToHost);

    for(j=0;j<N;j++){
        printf("A[ %d ]=%f \n",j,A[j]);
    }
    getchar();

    cudaFree(A_d);
    cudaFree(B_d); …
Run Code Online (Sandbox Code Playgroud)

c++ cuda gpgpu visual-studio-2010 visual-studio

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

将整数乘以分数和小数时,Python程序出错

我试图制作一个简短的程序来解决着名的德雷克方程.我让它接受整数输入,十进制输入和小数输入.但是,当程序试图将它们相乘时,我收到此错误(在我输入所有必要值之后,错误发生):

Traceback (most recent call last)
  File "C:/Users/Family/Desktop/Programming/Python Files/1/DrakeEquation1.py", line 24, in <module>
    calc() #cal calc to execute it
  File "C:/Users/Family/Desktop/Programming/Python Files/1/DrakeEquation1.py", line 17, in calc
    calc = r*fp*ne*fl*fi*fc*l
TypeError: can't multiply sequence by non-int of type 'str'
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

def intro():
    print('This program will evaluate the Drake equation with your values')

def calc():
    print('What is the average rate of star formation in the galaxy?')
    r = input()
    print('What fraction the stars have planets?')
    fp = input()
    ne = int(input('What is …
Run Code Online (Sandbox Code Playgroud)

python math equation

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

用于所有分配变量名称的空间

其实我刚开始学习C语言.我想知道变量名在哪里存储在C的内存中.请考虑以下代码:

int i = 10;
Run Code Online (Sandbox Code Playgroud)

我无法找到名称" i"存储在内存中的位置.

c variables

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

为什么gcc不给我警告或错误?

我创建了共享库:

lib.h:

int fun( int a, int b);
Run Code Online (Sandbox Code Playgroud)

lib.cpp:

#include <lib.h>

int fun ( int a, int b)
{
    return a+b;
}
Run Code Online (Sandbox Code Playgroud)

编译它:

gcc -fPIC -c lib.cpp gcc -shared -o -I ./header lib.so lib.o

我的lib.h位于./header中.因此,汇编已经成功.之后我改变了lib.cpp:

#include <lib.h>

int fun ( int a)
{
    return a;
}
Run Code Online (Sandbox Code Playgroud)

但什么也没发生.我想看到错误消息或警告.为什么?

c++ gcc

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