几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » SolidWorks二次开发
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-04-13, 12:59 PM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】multithreaded achievement of sw api

multithreaded achievement of sw api
hi!
i have a quad core computer. if i use the conventional sw connetion method, only 1 processor working.
i would like to push the advantage of the four processors, and i like to cut my job for 4 thread, after the threads run in paralel...)
i like create more instance of sw api, afterwards these the instance to separate threads to order.
it is possible? (i use c++ and com)
hresult hcomres = coinitializeex(null, coinit_multithreaded);
if (hcomres != s_ok)
{
cout << "error under initializing com. exiting..." << endl;
return 1;
}
ccomptr swapp;
ccomptr swapp2;
hresult hres1 = swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server);
hresult hres2 = swapp2.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server);
this code is bad, bacause the pointers swapp and swapp2 is equal.
thanks!
regards:
zszs.
you need to start a new instance of sw, get its pid (process id), then call
i say thank you for your answer, i will try it.
did i understand well?
the 1. initialize the com port ( coinitializeex(null, coinit_multithreaded) ) ,
the 2. i create 4 threads,
the 3. in all threads a sw i create an object instance ( swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server) ) ,
the 4. i call for all threads the setthreadaffinitymask() function.
regards:
zszs.
thats basically it yes. it is a theory i have thought of and presume will work but have not tested anything so let me know your results.
is disappearing in that manner works!
i opened it only temporarily and i closed it two different documentumot on the two threads.
my sample-code:
--------------------
#include "sldworks_api_session.h"
#include "thread.h"
#include "util.h"
using namespace std;
struct parthread
{
ccomptr{isldworks} swapp;
string docname;
};
std::vector{parthread} vecthreadparams;
dword winapi workproc(lpvoid pparam);
int _tmain(int argc, _tchar* argv[])
{
hresult hres = coinitializeex(null, coinit_multithreaded);
if (hres != s_ok)
{
cout << "error under initializing com. exiting..." << endl;
return 1;
}
int par1 = 0, par2 = 1;
parthread pt1, pt2;
pt1.docname = "d:\\x\\labe00_01001\\labe00_01001.sldasm";
pt2.docname = "d:\\x\\labj00_01001\\labj00_01001.sldasm";
vecthreadparams.push_back(pt1);
vecthreadparams.push_back(pt2);
thread* thr1 = new thread(workproc, &par1);
thread* thr2 = new thread(workproc, &par2);
thr1->resume();
thr2->resume();
while( (thr1->getexitcode() == still_active) || (thr2->getexitcode() == still_active) );
delete thr1;
delete thr2;
for(int i=0; i<=vecthreadparams.size()-1; i++)
vecthreadparams.swapp = null;
couninitialize();
return 0;
}
dword winapi workproc(lpvoid pparam)
{
int* paridx = (int*) pparam;
hresult hres = vecthreadparams[*paridx].swapp.cocreateinstance(__uuidof(sldworks), null, clsctx_local_server);
isldworks* papp = vecthreadparams[*paridx].swapp;
string docname = vecthreadparams[*paridx].docname;
ccomptr{imodeldoc2} swdoc;
string outmsg;
long er, wa;
hres = papp->opendoc6(util::str2bstr(docname), swdocassembly, swopendocoptions_silent, _bstr_t(""), &er, &wa, &swdoc);
if( (hres == s_ok) && (swdoc) )
{
outmsg = "thread:" + util::i2s(*paridx) + " opened.";
hres = papp->closedoc(util::str2bstr(docname));
}
else
outmsg = "thread:" + util::i2s(*paridx) + " error.";
cout << outmsg << endl;
swdoc = null;
return 0;
}
-----------------
comments:
1. the system took the words written between the pointed brackets out unfortunately! (pointed brackets template classes we are useful the c in c++) i changed the {} pairs instead of pointed brackets.
2. the "util" and "thread" classes they are my classes.
3. i don't use the setthreadaffinitymask() function. the system put the threads difference processor in default.
i say thank you for your idea!
regards:
zszs.
edited: 10/29/2008 at 04:14 am by zsolt zsupán
glad it worked, others should find this very useful for processor intensive tasks where time is critical
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭

相似的主题
主题 主题发起者 论坛 回复 最后发表
【转帖】external file references and sw api yang686526 SolidWorks二次开发 0 2009-04-13 10:50 AM
【转帖】api code speed and sw menu activation yang686526 SolidWorks二次开发 0 2009-04-13 08:56 AM
【转帖】外挂开发中的封包技术 huangyhg vc编程 0 2007-12-03 04:41 PM
How to start SW 2007 or SW 20006 via SW API? If I have two different versions of SW yogy SolidWorks二次开发 1 2007-05-21 09:19 AM
【转帖】对于hook函数的一点认识 huangyhg vc编程 0 2007-03-27 11:53 AM


所有的时间均为北京时间。 现在的时间是 04:32 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多